제출 #1136544

#제출 시각아이디문제언어결과실행 시간메모리
1136544onlk97송금 (JOI19_remittance)C++20
55 / 100
112 ms16088 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
using pii=pair <int,int>;
using tii=pair <pii,int>;
void solve(){
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for (int i=1; i<=n; i++) cin>>a[i]>>b[i];
    for (int i=1; i<=n; i++) a[i]-=b[i];
    bool hv=0;
    for (int i=1; i<=n; i++) if (b[i]) hv=1;
    if (!hv){
        for (int i=1; i<=n; i++){
            if (a[i]){
                cout<<"No\n";
                return;
            }
        }
        cout<<"Yes\n";
        return;
    }
    int ths=0;
    for (int i=1; i<=n; i++) ths+=a[i]*(1ll<<(i-1));
    if (ths<0||ths%((1ll<<n)-1)){
        cout<<"No\n";
        return;
    }
    ths/=((1ll<<n)-1);
    for (int i=1; i<=n; i++){
        ths+=a[i];
        if (ths<0||ths%2){
            cout<<"No\n";
            return;
        }
        ths/=2;
    }
    cout<<"Yes\n";
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t=1;
    //cin>>t;
    while (t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...