# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
749058 | 2023-05-27T09:38:13 Z | 1075508020060209tc | Coin Collecting (JOI19_ho_t4) | C++14 | 1 ms | 340 KB |
#include<bits/stdc++.h> using namespace std; #define int long long int n; int freq[4][500005]; int ps[3][500005]; int ans; signed main(){ cin>>n; ans=0; for(int i=1;i<=n*2;i++){ int a;int b; cin>>a>>b; if(b<=1){ ans+=abs(b-1); b=1; }else{ ans+=abs(b-2); b=2; } if(a<=1){ ans+=abs(1-a); a=1; } if(a>=n){ ans+=abs(n-a); a=n; } freq[b][a]++; } for(int i=1;i<=n;i++){ ps[1][i]=ps[1][i-1]+freq[1][i]; ps[2][i]=ps[2][i-1]+freq[2][i]; ps[3][i]=ps[1][i]+ps[2][i]; } int cnta=0;int cntb=0; int lst=0; for(int i=1;i<=n;i++){ if(ps[3][i]-i*2==0){ ans+=abs(ps[2][i]-ps[2][lst]-(i-lst) ); } ans+=abs(ps[3][i]-ps[3][lst]-(i-lst)*2); if(ps[3][i]-ps[3][lst]-(i-lst)*2==0){ lst=i; } } cout<<ans<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Incorrect | 0 ms | 340 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Incorrect | 0 ms | 340 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Incorrect | 0 ms | 340 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |