|
|
back to boardWA on test #9 Posted by INSOS 31 May 2019 16:40 Please give test-case -9 for this problem MY code # include <bits/stdc++.h> using namespace std; typedef long long intt; map <intt, intt> mp; map <intt, bool> mb; set <intt> st; map <set <intt>, intt> mst; int gcd(intt a, intt b) { return (b == 0) ? a : gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); intt n, ans = 0; cin >> n; for(intt i = 0; i < n; i++) { char c; intt m; cin >> c >> m; // cout << i << " " << c << " " << m << endl; if(c == '+') { mp[m]++; if(mb[m] == false) { st.insert(m); mb[m] = true; ans = gcd(ans, m); mst[st] = ans; } } else if (c == '-') { mp[m]--; if(!mp[m]) { st.erase(m); mb[m] = false; if(mst[st] != 0) { ans = mst[st]; } else if(st.size() != 0) { ans = 0; for(set <intt> :: iterator j = st.begin(); j != st.end(); j++) { ans = gcd(ans, *j); } } } } if(st.size() == 0) { cout << "1\n"; } else { cout << ans << "\n"; } } return 0; } Re: WA on test #9 Try this test: 6 + 81 - 81 + 14 - 14 + 17 + 85 Re: WA on test #9 Posted by INSOS 5 Jun 2019 19:31 thanks!! |
|
|