Python too slow? Translate to C++ with OpenAI API

Revision en1, by huikang, 2022-03-31 09:32:23

I used OpenAI API to translate Python code written by Kiri8128 in the recent combined division contest. These are the results.

How to use the translation tool

  • You will need an email and a phone number to sign up for the OpenAI Beta.
  • Create a new code translation Playground.
  • Press "Submit" to see an example of how the code is generated for Haskell.
  • Change Haskell to C++ in the starting prompt and at the stop sequence. You can see how C++ code is generated as well.
  • Insert the Python code you want to translate.
  • Change the maximum length to a larger number so that you generate the code all at once. The total number of tokens in the input and output is limited to 4000.
  • Copy code from Kiri8128.
  • Press "Submit" to generate the code.
  • Copy the C++ code and submit to Codeforces.

Kiri8128 is the first to reach Grandmaster with python3/pypy3 without ever switching to C++. Kiri8128 writes clean code which probably made it easier for the model to translate.

I am curious to see if this tool can produce code that resolves the various instances where Kiri8128's Python code TLE or MLE. I haven't been successful, as the code that seem to TLE/MLE because of the language is usually the more complicated ones.

Feel free to share your thoughts and findings!

Tags python, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English huikang 2022-03-31 09:32:23 2725 Initial revision (published)