Submission #335825

# Submission time Handle Problem Language Result Execution time Memory
335825 2020-12-14T05:01:12 Z blue Remittance (JOI19_remittance) C++11
0 / 100
1 ms 380 KB
#include <iostream>
using namespace std;

/*
Let T[i] be the total number of yen transferred from i to i+1
A[i] - B[i] == 2*T[i] - T[i-1]
A[i+1] - B[i+1] == 2*T[i+1] - T[i]
T[i] = 2*T[i+1] + B[i+1] - A[i+1]
*/

long long N;
long long A[1000001];
long long B[1000001];
long long sumT = 0;

void b_search(long long l, long long r)
{
    //cout << l << ' ' << r << '\n';
    if(l == r)
     {
        long long temp = r;
        long long S = r;
        //cout << r << ' ';
        for(long long i = N-1; i >= 1; i--)
        {
            temp = 2*temp + B[i+1] - A[i+1];
            if(temp < 0)
            {
                cout << "No\n";
                return;
            }
            S += temp;
        //    cout << temp << ' ';
        }
        //cout << '\n';
        if(r == 2*temp + B[1] - A[1] && S == sumT) cout << "Yes\n";
        else cout << "No\n";
        return;
    }

    long long m = (l+r)/2;
    long long S = m;
    long long temp = m;
    //cout << m << ' ';
    for(long long i = N-1; i >= 1; i--)
    {
        //cout << i << ' ';
        temp = 2*temp + B[i+1] - A[i+1];
        if(temp < 0)
        {
            b_search(m+1, r);
            return;
        }
        S += temp;
    //    cout << "hello" << ' ' << temp << ' ';
    }
    //cout << '\n'; 
    if(S >= sumT) b_search(l, m);
    else b_search(m+1, r);
}

int main()
{
    cin >> N;

    for(long long i = 1; i <= N; i++)
    {
        cin >> A[i] >> B[i];
        sumT += A[i] - B[i];
    }

    if(sumT < 0)
    {
        cout << "No\n";
        return 0;
    }

    b_search(0, 1000000000000000);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 236 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 236 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 236 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -