Getting wrong answer when submitting but in local I'm getting correct answer.

Revision en1, by AnestheticCoder, 2021-11-29 17:17:01

C. Delete Two Elements 1598C - Delete Two Elements 137345565

I'm solving 1598C Delete two elements

When I submit the problem I get a wrong answer saying expected was 10 but found 0 but when I copy the same test case and run it in my machine I'm getting 10. I just need help to verify if my logic to solving this question along with my implementation is correct. Please help.

My Solution:-

pragma GCC optimize("Ofast")

pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

pragma GCC optimize("unroll-loops")

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

define endl "\n"

using namespace std;

typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector vl; typedef vector vi; typedef vector<vector > vvi; typedef vector<vector > vvl;

int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);

ifdef D_DEBUG

freopen("input.txt", "r", stdin)

endif

int tc;

cin >> tc; while (tc--) { int n; cin >> n; vector input(n); for (int i = 0; i < n; ++i) { cin >> input[i]; } ll sum = accumulate(input.begin(), input.end(), 0l); ll answer = 0; //cout<<sum<<endl; unordered_map<int, int> freq; if (((2 * sum) % n) == 0) { int val = (2 * sum) / n; for (int i = 0; i < n; ++i) { freq[input[i]]++; } sort(input.begin(),input.end()); vector::iterator end = unique(input.begin(), input.end()); input.resize(distance(input.begin(), end)); for (int i = 0; i < input.size(); ++i) { int first = input[i]; int second = val — first; if(first==second){ answer += (freq[first]*1ll*(freq[first]-1))/2; } else { answer += freq[first]*freq[second]; } freq[first]=0; } } cout << answer << endl; } }

Tags math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English AnestheticCoder 2021-11-29 17:19:37 75
en2 English AnestheticCoder 2021-11-29 17:18:32 26
en1 English AnestheticCoder 2021-11-29 17:17:01 2426 Initial revision (published)