514A - Chewbaсca and Number Hello! I am relatively new to CF and CP overall, but I was wondering if someone more experienced can look at this problem and check whether my solution to this test case is incorrect or if there is an issue with the test solution. As you can see, I got the least possible positive number with the problem conditions but the test is saying I am incorrect.

Test Case

Auto comment: topic has been updated by nithilanm (previous revision, new revision, compare).https://codeforces.com/contest/514/submission/270569977 you can see my logic here we just need to invert the digit with the value>=5 but we ignore the exceptional case of when there is 9 as the first digit because when we invert it would become zero leading to invalid number as there the leading zeros are not allowed then we don't perform operation.

Yeah,the problem statement is a bit unclear and I too faced this issue. Maybe the crux is that it says "The decimal representation shouldn't start with 0" So,I changed the condition that if the first digit is 9 then don't change it, otherwise make it min(t,9-t) and then it got accepted.

My solution was to invert all nums less than or equal to '5', and if the final output was '0' i'd invert it and output "9" instead. This solution is the optimal one in theory, but we need to fit the testcases ig. Alright, thank you!

It said you cannot make the first digit 0 ..in meant you cannot change the number of digits...

Yes, exactly. I too was wondering after 5 WA what was up then read it again to find out

They never said you can't make the first digit zero. They said no leading zeros in the final decimal representation of the number. So if you have 900, you can make it 009 and then remove the leading zeros for the final representation. I understand the confusion here, but I do believe my code answers the question posed and not the one intended by the problem creators.

int main() {

cout << ans; return 0;

}

basically if digit > 4, we transform it. sole exception being that if i == 0 and digit == 9, in this case we skip the transformation, as asked in the question.