Submission #263415

# Submission time Handle Problem Language Result Execution time Memory
263415 2020-08-13T16:46:25 Z Falcon Remittance (JOI19_remittance) C++14
0 / 100
1 ms 384 KB
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int TOO_LESS = -1, TOO_MUCH = 1;

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    int n;
    cin >> n;
    vi A(n), b(n);
    rep(i, n) cin >> A[i] >> b[i];	
    debug(A, b);
    auto check = [=](int x, vi a){
    	debug(a, x);
    	a[n - 1] -= x << 1;
    	a[0] += x;
    	rep(i, n - 1){
    		debug(a[i], b[i])
    		if(a[i] < b[i]) 
    			return TOO_LESS;
    		else
    			a[i + 1] += (a[i] - b[i]) >> 1, a[i] = b[i];
    	}
    	debug(a);
    	if(a[n - 1] < b[n - 1])
    		return TOO_MUCH;
    	else if(a[n - 1] > b[n - 1])
    		return TOO_LESS;
    	return 0;
    };

    int s = 0, e = A[n - 1] / 2;
    debug(s, e);
    while(s <= e){
    	int m = (s + e) >> 1;
    	int t = check(m, A);
    	if(t == TOO_LESS)
    		s = m + 1;
    	else if(t == TOO_MUCH)
    		e = m - 1;
    	else{
    		cout << "Yes\n";
    		return 0;
    	}
    }

    cout << "No\n";

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -