Submission #773779

# Submission time Handle Problem Language Result Execution time Memory
773779 2023-07-05T08:28:00 Z CyberCow Remittance (JOI19_remittance) C++17
0 / 100
3 ms 468 KB
//#include <bits/stdc++.h>
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 1000005;
ll a[N], b[N];

void solve()
{
    ll n, i, j, x, y, gum1 = 0, gum = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
        gum += a[i];
        gum1 += b[i];
    }
    i = 0;
    int st = 0, qan = 0;
    while (1)
    {
        qan++;
        i++;
        if (i == n + 1)
        {
            int st = 1;
            for ( j = 1; j <= n; j++)
            {
                if (a[j] != b[j])
                    st = 0;
            }
            if (st)
            {
                cout << "Yes";
                return;
            }
        }
        if (i < n)
        {
            if (a[i] > b[i])
            {
                if (a[i] - (a[i] - b[i] + 1) / 2 * 2 >= 0)
                {
                    gum -= (a[i] - b[i] + 1) / 2 * 2;
                    gum += (a[i] - b[i] + 1) / 2;
                    a[i + 1] += (a[i] - b[i] + 1) / 2;
                    a[i] -= (a[i] - b[i] + 1) / 2 * 2;
                }
                else
                {
                    gum -= (a[i] - b[i] + 1) / 2 * 2 - 2;
                    gum += (a[i] - b[i] + 1) / 2 - 1;
                    a[i + 1] += (a[i] - b[i] + 1) / 2 - 1;
                    a[i] -= (a[i] - b[i] + 1) / 2 * 2 - 2;
                }
            }
        }
        else
        {
            if (a[i] > b[i])
            {
                if (a[i] - (a[i] - b[i] + 1) / 2 * 2 >= 0)
                {
                    gum -= (a[i] - b[i] + 1) / 2 * 2;
                    gum += (a[i] - b[i] + 1) / 2;
                    a[1] += (a[i] - b[i] + 1) / 2;
                    a[i] -= (a[i] - b[i] + 1) / 2 * 2;
                }
                else
                {
                    gum -= (a[i] - b[i] + 1) / 2 * 2 - 2;
                    gum += (a[i] - b[i] + 1) / 2 - 1;
                    a[1] += (a[i] - b[i] + 1) / 2 - 1;
                    a[i] -= (a[i] - b[i] + 1) / 2 * 2 - 2;
                }
            }
        }
        if (qan >= 100000000)
            break;
    }
    if (n <= 7)
    {
        if (gum == gum1)
            cout << "Yes";
        else
            cout << "No";
    }
    else
    {
        if(gum == gum1)
            cout << "Yes";
        else
            cout << "No";
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Compilation message

remittance.cpp: In function 'void solve()':
remittance.cpp:33:17: warning: unused variable 'x' [-Wunused-variable]
   33 |     ll n, i, j, x, y, gum1 = 0, gum = 0;
      |                 ^
remittance.cpp:33:20: warning: unused variable 'y' [-Wunused-variable]
   33 |     ll n, i, j, x, y, gum1 = 0, gum = 0;
      |                    ^
remittance.cpp:42:9: warning: unused variable 'st' [-Wunused-variable]
   42 |     int st = 0, qan = 0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -