### nithilanm's blog

By nithilanm, history, 3 weeks ago,

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

• -1

 » 3 weeks ago, # |   0 Auto comment: topic has been updated by nithilanm (previous revision, new revision, compare).
•  » » 3 weeks ago, # ^ | ← Rev. 2 →   0 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.
 » 3 weeks ago, # |   0 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.
•  » » 3 weeks ago, # ^ | ← Rev. 2 →   0 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!
•  » » » 3 weeks ago, # ^ |   0 It said you cannot make the first digit 0 ..in meant you cannot change the number of digits...
•  » » » » 3 weeks ago, # ^ |   0 Yes, exactly. I too was wondering after 5 WA what was up then read it again to find out
•  » » » » 3 weeks ago, # ^ |   0 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.
 » 3 weeks ago, # |   0 int main() { string s; cin >> s; string ans ; for (int i = 0; i < s.size(); i ++){ char cur = s[i]; int digit = cur - '0'; if (digit > 4) { digit = 9 - digit; if (i== 0 and digit == 0){ digit = 9; } } ans += to_string(digit); }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.