Submission #483413

#TimeUsernameProblemLanguageResultExecution timeMemory
483413Lam_lai_cuoc_doiRemittance (JOI19_remittance)C++17
100 / 100
223 ms36296 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 1e6 + 5;
int n;
ll a[N], b[N];

void Read()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i] >> b[i];
}

void Send(int pos, ll v)
{
    a[pos] -= v * 2;
    ++pos;
    if (pos > n)
        pos = 1;
    a[pos] += v;
}

void Solve()
{
    while (1)
    {
        bool ok(1);
        for (int i = 1; i <= n; ++i)
            if (a[i] > b[i])
            {
                ll v = (a[i] - b[i]) / 2;
                if (v == 0 && a[i] > 1)
                    Send(i, 1), ok = 0;
                if (v > 0)
                    Send(i, v), ok = 0;
            }
        if (ok)
            break;
    }

    for (int i = 1; i <= n; ++i)
        if (a[i] != b[i])
        {
            cout << "No";
            return;
        }
    cout << "Yes";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (fopen(".INP", "r"))
    {
        freopen("and.inp", "r", stdin);
        freopen("and.out", "w", stdout);
    }
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        // cout << "Case #" << _ << ": ";
        Read();
        Solve();
    }
    // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

Compilation message (stderr)

remittance.cpp: In function 'void read(T&)':
remittance.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
remittance.cpp: In function 'int32_t main()':
remittance.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("and.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
remittance.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("and.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...