My code for problem 1742B in Codeforces:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, n;
cin >> a;
vector<int> v;
for (int i = 0; i < a; i++) {
cin >> n;
v.push_back(n);
}
sort(v.begin(), v.end());
int cnt = 0;
for (int i = 0; i < a; i++) {
if (v[i] >= v[i - 1] && v[i] != v[i - 1]) {
cnt++;
}
}
if (cnt >= a) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
For the given test case in the problem, Replit (where I write it) gave the correct answer (no/yes/yes), but when I submitted it to Codeforces, it gave the wrong answer (no/yes/no) for the same test case. When I put it into GDB to debug, it gave the same answer (correct) as Replit and exited normally. Is there something wrong with the code and why are they outputting different answers?
as far as I know there are no non-initialization shenanigans happening, and I’m not sure what else there could be to mess things up. no compilation errors, just wrong answer.
Ash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.