Submission #915967

# Submission time Handle Problem Language Result Execution time Memory
915967 2024-01-25T04:06:55 Z ReLice Coin Collecting (JOI19_ho_t4) C++14
100 / 100
150 ms 7472 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
template <class _T>
bool chmin(_T &x, const _T &y){
    bool f=0;
    if (x>y){x=y;f=1;}
    return f;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool f=0;
    if (x<y){x=y;f=1;}
    return f;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
void solve(){
    ll i,j;
    ll n;
    cin>>n;
    ll a[n+1][3];
    memset(a,0ll,sizeof(a));
    ll sum=0;
    for(i=1;i<=2*n;i++){
        ll x,y;
        cin>>x>>y;
        if(x<1){sum+=1-x;x=1;}
        if(x>n){sum+=x-n;x=n;}
        if(y<1){sum+=1-y;y=1;}
        if(y>2){sum+=y-2;y=2;}
        a[x][y-1]++;
    }
    deque<ll> v,v2;
    for(i=1;i<=n;i++){
        if(a[i][0]==0)v.pb(i);
        if(a[i][1]==0)v2.pb(i);
        while(a[i][0]>1 && v.sz){
            sum+=i-v[0];
            a[i][0]--;
            v.pof;
        }
        while(a[i][1]>1 && v2.sz){
            sum+=i-v2[0];
            a[i][1]--;
            v2.pof;
        }
        while(v.sz && a[i][1]>1){
            sum+=i-v[0]+1;
            a[i][1]--;
            v.pof;
        }
        while(v2.sz && a[i][0]>1){
            sum+=i-v2[0]+1;
            a[i][0]--;
            v2.pof;
        }
        if(a[i][0]>1){
            a[i+1][0]+=a[i][0]-1;
            sum+=a[i][0]-1;
        }
        if(a[i][1]>1){
            a[i+1][1]+=a[i][1]-1;
            sum+=a[i][1]-1;
        }
    }
    cout<<sum<<endl;
}

signed main(){
	//start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*



*/

Compilation message

joi2019_ho_t4.cpp: In function 'void solve()':
joi2019_ho_t4.cpp:46:10: warning: unused variable 'j' [-Wunused-variable]
   46 |     ll i,j;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 436 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 436 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 3 ms 600 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 360 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 1 ms 480 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 344 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 2 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 436 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 3 ms 600 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 360 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 1 ms 480 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 344 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 2 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 63 ms 4176 KB Output is correct
66 Correct 130 ms 7248 KB Output is correct
67 Correct 100 ms 5812 KB Output is correct
68 Correct 108 ms 5716 KB Output is correct
69 Correct 107 ms 5716 KB Output is correct
70 Correct 104 ms 5812 KB Output is correct
71 Correct 99 ms 5948 KB Output is correct
72 Correct 100 ms 6480 KB Output is correct
73 Correct 102 ms 7472 KB Output is correct
74 Correct 100 ms 5972 KB Output is correct
75 Correct 98 ms 5936 KB Output is correct
76 Correct 100 ms 6188 KB Output is correct
77 Correct 100 ms 6588 KB Output is correct
78 Correct 99 ms 6204 KB Output is correct
79 Correct 114 ms 6320 KB Output is correct
80 Correct 99 ms 6484 KB Output is correct
81 Correct 101 ms 6188 KB Output is correct
82 Correct 99 ms 5972 KB Output is correct
83 Correct 99 ms 6064 KB Output is correct
84 Correct 100 ms 5936 KB Output is correct
85 Correct 101 ms 5936 KB Output is correct
86 Correct 100 ms 5940 KB Output is correct
87 Correct 99 ms 5932 KB Output is correct
88 Correct 98 ms 5716 KB Output is correct
89 Correct 107 ms 5968 KB Output is correct
90 Correct 99 ms 5828 KB Output is correct
91 Correct 100 ms 5716 KB Output is correct
92 Correct 100 ms 5972 KB Output is correct
93 Correct 101 ms 5808 KB Output is correct
94 Correct 97 ms 5684 KB Output is correct
95 Correct 95 ms 5716 KB Output is correct
96 Correct 104 ms 6996 KB Output is correct
97 Correct 103 ms 6992 KB Output is correct
98 Correct 113 ms 6076 KB Output is correct
99 Correct 100 ms 6740 KB Output is correct
100 Correct 100 ms 6340 KB Output is correct
101 Correct 150 ms 6708 KB Output is correct
102 Correct 103 ms 5952 KB Output is correct
103 Correct 102 ms 5968 KB Output is correct