Submission #610039

# Submission time Handle Problem Language Result Execution time Memory
610039 2022-07-28T04:33:42 Z czhang2718 Remittance (JOI19_remittance) C++17
100 / 100
231 ms 41284 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define int ll

const int N=1e6+1, mod=1e9+7;
int n;
ll a[N], b[N], c[N];
ll t[N];
ll pw[N];

ll bpow(ll a, ll b){
    if(b==0) return 1;
    ll x=bpow(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n;
    pw[0]=1;
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
        c[i]=b[i]-a[i];
        pw[i+1]=(pw[i]*2)%mod;
    }

    for(int i=n-1; i>=0; i--){
        t[0]+=pw[(i-1+n)%n]*(c[i]+mod)%mod;
        t[0]%=mod;
    }
    // cout << t[0] << "\n";
    t[0]=(mod-t[0])%mod;
    t[0]=(t[0]*(mod+bpow(mod+pw[n]-1, mod-2)))%mod;
    // cout << t[0] << "\n";

    for(int i=n-1; i>0; i--){
        t[i]=2*t[(i+1)%n]+c[(i+1)%n];
        if(t[i]<0){
            cout << "No"; return 0;
        }
    }

    while(true){
        bool used=0;
        for(int i=0; i<n; i++){
            if(t[i]){
                int take=min(t[i], a[i]/2);
                t[i]-=take;
                a[i]-=2*take;
                a[(i+1)%n]+=take;
                if(take) used=1;
            }
        }
        if(!used) break;
    }



    // for(int i=0; i<n-1; i++){
    //     int take=min(t[i], a[i]/2);
    //     t[i]-=take;
    //     a[i]-=2*take;
    //     a[i+1]+=take;
    // }
    // int i=n-1;
    // int take=min(t[i], a[i]/2);
    // if(take<t[i]){
    //     cout << "No"; return 0;
    // }
    // t[i]-=take;
    // a[i]-=2*take;
    // a[0]+=take;
    // for(int i=0; i<n-1; i++){
    //     int take=min(t[i], a[i]/2);
    //     if(take<t[i]){
    //         cout << "No"; return 0;
    //     }
    //     a[i]-=2*take;
    //     a[i+1]+=take;
    // }
    for(int i=0; i<n; i++){
        if(t[i] || a[i]!=b[i]){
            cout << "No"; return 0;
        }
    }
    cout << "Yes";
}
# 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 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# 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 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 324 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
# 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 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 324 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 205 ms 31584 KB Output is correct
64 Correct 143 ms 41248 KB Output is correct
65 Correct 214 ms 39396 KB Output is correct
66 Correct 139 ms 41284 KB Output is correct
67 Correct 144 ms 41156 KB Output is correct
68 Correct 152 ms 41232 KB Output is correct
69 Correct 205 ms 39496 KB Output is correct
70 Correct 108 ms 33400 KB Output is correct
71 Correct 128 ms 33504 KB Output is correct
72 Correct 130 ms 33352 KB Output is correct
73 Correct 191 ms 31584 KB Output is correct
74 Correct 149 ms 38792 KB Output is correct
75 Correct 137 ms 40228 KB Output is correct
76 Correct 146 ms 39732 KB Output is correct
77 Correct 209 ms 39268 KB Output is correct
78 Correct 188 ms 40784 KB Output is correct
79 Correct 148 ms 33024 KB Output is correct
80 Correct 175 ms 40816 KB Output is correct
81 Correct 162 ms 33040 KB Output is correct
82 Correct 122 ms 41196 KB Output is correct
83 Correct 112 ms 33456 KB Output is correct
84 Correct 126 ms 41236 KB Output is correct
85 Correct 231 ms 39464 KB Output is correct
86 Correct 220 ms 31632 KB Output is correct
87 Correct 199 ms 40796 KB Output is correct
88 Correct 191 ms 40852 KB Output is correct