답안 #478115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478115 2021-10-05T17:22:06 Z nicolaalexandra 송금 (JOI19_remittance) C++14
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>
#define DIM 100010
using namespace std;

int a[DIM],b[DIM],x[DIM],p[22];
int n,i;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i]>>b[i];

    if (n == 1){
        if (a[i] != b[i])
            cout<<"No";
        else cout<<"Yes";

        return 0;
    }

    if (n == 2){

        int val = a[1] - b[1] + 2 * (a[2] - b[2]);
        if (val % 3){
            cout<<"No";
            return 0;
        }

        x[2] = val / 3;

        if ( (a[1] - b[1] + x[2]) % 2){
            cout<<"No";
            return 0;
        }

        x[1] = (a[1] - b[1] + x[2]) / 2;

        if (x[1] < 0 || x[2] < 0){
            cout<<"No";
            return 0;
        }

        return 0;
    }

    p[0] = 1;
    for (i=1;i<=20;i++)
        p[i] = p[i-1] * 2;


    int val = p[n-1] * (a[1] - b[1]) + p[n-2] * (a[n] - b[n]);
    for (i=n-1;i>=2;i--)
        val += p[i-2] * (a[i] - b[i]);

    if (val % (p[n]-1)){
        cout<<"No";
        return 0;
    }

    x[1] = val / (p[n]-1);

    if (val < 0){
        cout<<"No";
        return 0;
    }

    for (i=2;i<=n;i++){
        int val = a[i] - b[i] + x[i-1];
        if (val % 2 || val < 0){
            cout<<"No";
            return 0;
        }
        x[i] = val / 2;
    }

    int ok = 0;
    for (i=1;i<=n;i++){
        int val = a[i] + x[ (i > 1) ? (i-1) : (n)  ] - 2 * x[i];
        if ( val != b[i] ){
            cout<<"No";
            return 0;
        }
        if (2 * x[i] <= a[i])
            ok = 1;
    }

    if (!ok)
        cout<<"No";
    else cout<<"Yes";


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -