photoshot_2020_Jan

Weird verdict by the Grader

Incorrect answer on sample input case ā€“ details below

Your output file photo.out: 3 1 5 2 4
The correct answer: 3 1 5 2 4

problem :point_right: http://www.usaco.org/index.php?page=viewproblem2&cpid=988

My code

int N; cin >> N;
 vector<int> b(N-1);
 for(auto &w : b) cin >> w; 
 vector<int> ans(N);
 for(int i = 0; i < N; i++){
     ans[i] = N - i;
 } 
 vector<int> v;
 set<int> ss;
 for(int i = 1; i <= N; i++){
     v.push_back(i);
     ss.insert(i);
     for(int j = 1; j < N; j++){
         int bck = v.back();
         v.push_back(b[j - 1] - bck);
         ss.insert(b[j - 1] - bck);
     } 
     if((int)ss,size() == N) ans = min(ans, v);   
     v.clear();
     ss.clear();
 }
 for(int i = 0; i < N; i++) cout << ans[i] << " ";

Why Iā€™m getting this ā€¦? help please

I believe that it is due to the extra whitespace at the end, in the line cout << ans[i] << " ";. (There should not be an extra space at the end of the line.) This can be fixed through an if statement that uses cout << ans[i] << "\n" instead of cout << ans[i] << " " exactly when i = N - 1.

More info here: https://usaco.guide/general/io#note---extra-whitespace

1 Like