# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136850 | 2019-07-26T11:01:56 Z | hamzqq9 | Coin Collecting (JOI19_ho_t4) | C++14 | 2 ms | 376 KB |
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define ppb pop_back #define ii pair<int,int> #define ll long long #define umin(x,y) x=min(x,y) #define umax(x,y) x=max(x,y) #define orta ((bas+son)>>1) #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define inf 2000000000 #define N 200005 #define MOD 998244353 using namespace std; ll ans; int n; int a[3][N]; int tot[4]; void solve() { // cerr << ans << "\n"; for(int i=1;i<=2;i++) { for(int j=1;j<=n;j++) { a[0][j]+=a[i][j]; tot[i]+=a[i][j]; } } ans+=abs(tot[1]-tot[2])/2; multiset<int> unvis,spread; for(int i=1;i<=n;i++) { if(a[0][i]<2) { while(sz(spread) && a[0][i]<2) { a[0][i]++; ans+=i-*spread.begin(); spread.erase(spread.begin()); } } else { while(min(a[0][i]-2,sz(unvis))) { ans+=i-*unvis.begin(); a[0][i]--; unvis.erase(unvis.begin()); } } for(int j=a[0][i];j<2;j++) { unvis.insert(i); } for(int j=2;j<a[0][i];j++) { spread.insert(i); } } } ll dst(ii a,ii b) { return (ll)abs(a.st-b.st)+abs(a.nd-b.nd); } ii fnear(int x,int y) { ii res; if(y>=2) res.nd=2; else res.nd=1; if(x>n) res.st=n; else if(x<1) res.st=1; else res.st=x; ans+=dst({x,y},res); return res; } int main() { scanf("%d",&n); for(int i=1;i<=n*2;i++) { int x,y; scanf("%d %d",&x,&y); ii near=fnear(x,y); a[near.nd][near.st]++; } // for(int i=1;i<=2;i++,cerr<<"\n") for(int j=1;j<=n;j++) cerr<<a[i][j]<<" "; solve(); printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 376 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 376 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 376 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |