Submission #610801

# Submission time Handle Problem Language Result Execution time Memory
610801 2022-07-28T14:35:20 Z czhang2718 Remittance (JOI19_remittance) C++17
0 / 100
1 ms 340 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;
        }
    }
 
    for(int it=0; it<2; it++){
      for(int i=0; i<n; i++){
          int take=min(t[i], a[i]/2);
          t[i]-=take;
          a[i]-=2*take;
          a[i+1]+=take;
      }
    }
    
    if(t[n-1]){
        cout << "No"; return 0;
    }
    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 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -