balllightning37's blog

By balllightning37, history, 17 months ago, In English

Do you want to be at the top of a CSES leaderboard? Are you tired of your friends complaining that your code is impossible to read? Do you just want to solve the problem in one line? Here's how.

Step 1: Actually solve the problem. However, you must write a correct solution in Python. It doesn't matter how long your solution is, but make sure everything is an ASCII character.

Step 2: Save your solution as "in.py" in the same folder as the following Python script:

f=open('in.py','r')
output='exec("".join(chr(len(i)) for i in "'
for l in f.readlines():
    for ch in l:
        output+=(" "*ord(ch))
        output+=chr(9)
output=output[:-1]+'".split("	")))'
f.close()
with open('out.py','w') as g:
    g.write(output)

Step 3: Run the program to produce "out.py". This will run reasonably fast as long as "in.py" isn't as fat as your mom.

Step 4: Submit "out.py". Guaranteed to work if your original solution is correct and the output file is not too large.

Step 5: Profit. CSES will always think that this is 44 characters, much smaller than your original solution! Codeforces does not keep track of solution length, but it still works nonetheless.

Proof that it works:

Just look how this ugly ahhh trash 318273437 became this beautiful enlightening masterpiece 318273465. This strategy works so well that it even confuses Mike to make your code run a few milliseconds faster!

How it works:

Your code is technically a string of ASCII characters. The python exec() function executes the string inside as python code, so it suffices to encode your solution with whitespace. That is done by using $$$k$$$ spaces (ASCII char 32) in a row followed by a tab (ASCII char 9) to encode the ASCII character numbered $$$k$$$. CSES doesn't count whitespaces or tabs towards characters, so any solution will be 44 characters!

Disclaimer 1: you accept any emotional damage, skipped solutions, or cheating allegations caused to you or others by using this method

Disclaimer 2: this is not my original idea, my friend showed me a some other person's submission that did this

  • Vote: I like it
  • +261
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
 
Vote: I like it +26 Vote: I do not like it

Wow, what the hell, this is so cool lmao

»
17 months ago, hide # |
 
Vote: I like it +21 Vote: I do not like it

This also made the code run 32ms faster!

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Codegolfers in shambles rn

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

CSES leaderboards boutta be flooded w/ 44 char submissions soon.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is this limited to python? Is it possible with cpp

»
16 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

This can be done in 34.

»
16 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

CSES doesn't count whitespaces or tabs towards characters

meanwhile this language literally menacing for a judge with this feature

»
8 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

someone did it in 16 characters using ruby https://cses.fi/problemset/hack/1748/entry/15662438/

EDIT: you probably need to solve this problem first to see the submission https://cses.fi/problemset/task/1748/