### parth_2003's blog

By parth_2003, history, 4 weeks ago,

So I was solving Question Chess Tournament 1569B rated 1000. when I submit the code then the output on the given test cases are showing wrong, Although I checked them on my compiler, and the code was working fine. Here is the code,

# include<bits/stdc++.h>

using namespace std;

int main(){ int t; cin >> t; while(t--){ int n; cin >> n; vector v(n); int countO=0; int countT=0; for(int i=0; i<n; i++){ cin >> v[i]; if(v[i] == 1){ countO++; } else{ countT++; } } if(countT == 2 || countT == 1){ cout << "NO" << endl; continue; }

vector<vector<char> > f(n, vector<char>(n, '='));
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i == j){
f[i][j] = 'X';
}
else if(v[i] == 1 && v[j] == 2){
f[i][j] = '+';
}
else if(v[i] == 1 && v[j] == 1){
f[i][j] = '=';
}
}
}

vector<int> type2;
for(int i=0; i<n; i++){
if(v[i] == 2){
type2.push_back(i);
}
}
for(int i=0; i<type2.size(); i++){
int curr = type2[i];
int next = type2[i+1 % (type2.size())];
f[curr][next] = '+';
f[next][curr] = '-';
}

cout << "YES" << endl;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout << f[i][j];
}
cout << endl;
}


} }

• -19

 » 4 weeks ago, # | ← Rev. 2 →   0 You have to fix this line of code:int next = type2[i+1 % (type2.size())];
•  » » 4 weeks ago, # ^ |   0 can you please tell the reason for this? is it because type2.size() is size_t datatype?
•  » » » 4 weeks ago, # ^ |   0 % operator has higher priority than +, so it's actually translated as type2[i + (1 % (type2.size())], which is unintended and gets out of the vector's range when i + 1 == type2.size().
•  » » » » 4 weeks ago, # ^ |   0 understood, thank you
 » 4 weeks ago, # | ← Rev. 2 →   0 deleted
 » 4 weeks ago, # |   0 265461929 Can someone explain why it says expected: '1005355647', found: '1005355648' even though when I run the same testcase on my compiler it gives 1005355647 as output. Pretty confused TBH.
•  » » 4 weeks ago, # ^ |   0 its because of the sqrt() that you are using i guess????
•  » » » 4 weeks ago, # ^ |   0 It gives different outputs in different compilers? I ran it on online GDB, the same code... it gives the correct output, try to run on your own device. 1 77921270569329490 377318254283917957
•  » » » » 4 weeks ago, # ^ | ← Rev. 3 →   0 yeah, its wrong with the cf compiler maybe, look at thissubmission with GNU G++ 14 6.4.0 i got WA in 11tc here; but submission with GNU G++ 20 i got WA in 4thc tcalso, you will get same type of error with the "pow()" function too
 » 4 weeks ago, # |   0 No.