There is an inconsistency in output in my system and codeforces environment. Following is my implementation. https://mirror.codeforces.com/contest/2037/submission/292083626 Test case 1: 2 1 4 5 3 3 my output in codeforces is shown as 2 2 but when I run it else anywhere (online and my machine) its giving 1 4.
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; void solve(){ int len; cin>>len; vector<int> v(len); for(auto& x: v) cin>>x; int target=len-2; unordered_map<int, int, custom_hash> umap; for(auto x: v){ if (target%x!=0) continue; umap[x]++; } for (auto& it: umap){ int num = it.first; int second=target/num; if ((second==num) && (it.second>1)){ cout<<num<<" "<<num<<endl; return; } else if (umap.find(second) !=umap.end()){ cout<<num<<" "<<second<<endl; return; } } } int main(){ int testNum; cin >> testNum; while(testNum--){ solve(); } }
Can anyone help me understand what is going wrong here?
unordered map is... well... unordered
there can be more than one pair of solution and it'll output a random one
But here I am checking count through unordered map. So for '2' in testcase count is 1 Hence 2,2 should not come and its not coming in my machine also.
It is coming from else part IMO
That part should give same wrong output on all machines right? Is there any possibility of unordered map having memory mix up issue in codeforces in case of multiple test cases?
It is captured in previous comment
unordered map is... well... unordered
Thanks. Using ordered map has solved my problem. But I still have the doubt why unordered map is giving issue.
I had the same problem using sets in python, I only change Pypy to Python compiler and got accepted, so weird lmao
Pypy WA: 291981466
Python 3.10 AC: 291983507
I submits the exactly same code and passes: 292088616.
I also invocates the exactly same code for 10+ times and it also gives me correct answer.
I am confused now.
Weird right! Different output for different user!!
I HAVE WRITTEN THE CODE IN JAVA AND USED A DIFFERENT APPROACH BUT ITS GETTING WRONG ANSWER ANYONE COULD SUGGEST THE CHANGE NEEDED PLEASE...
THIS GETS THE ANSWER 3 2 FOR LAST TEST OF EXAMPLE TEST CASE BUT IT WASNT ACCEPTED SO PLEASE SUGGEST THE CHANGES NEEDED