Why Isn’t My Answer Submitting Even When It’s Right?

Revision en4, by EyeSpirit, 2024-12-09 20:34:26

Hey everyone! I’m relatively new to competitive programming and have been diving into platforms like Codeforces lately. It’s been an exciting but humbling experience, and I’m constantly learning. If you have any advice for improving problem-solving skills or tackling contests efficiently, I’d love to hear it!

Now, let me share a recent puzzling experience I had while solving a problem on Codeforces. The question was about array cloning (a common problem type involving arrays). I spent a lot of time debugging and perfecting my solution in C++17, only to have it rejected 10 times in a row. To my surprise, when I switched to C++20, the very same code passed without issues. The code is given down below you can check for your self.

#include <bits/stdc++.h>
#define ll long long
#define pp pair<int, int>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> v(n);
        int maxf = 0;
        unordered_map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> v[i];
            mp[v[i]]++;
            maxf = max(maxf, mp[v[i]]);
        }
        int req = n &mdash; maxf;
        int step = 0;
        while (maxf < n) {
            maxf *= 2;
            step++;
        }
        step += req;
        cout << step << endl;
    }
}
Tags coding

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English EyeSpirit 2024-12-09 20:35:28 8 Tiny change: 't req = n &mdash; maxf;\n ' -> 't req = n - maxf;\n '
en4 English EyeSpirit 2024-12-09 20:34:26 2 Tiny change: 'ur self.\n```cpp\n' -> 'ur self.\n\n```cpp\n'
en3 English EyeSpirit 2024-12-09 20:33:51 73
en2 English EyeSpirit 2024-12-09 20:27:26 6
en1 English EyeSpirit 2024-12-09 20:22:16 1434 Initial revision (published)