답안 #893732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893732 2023-12-27T10:35:01 Z Alcabel 송금 (JOI19_remittance) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
const long long mod = 1e9 + 7;
#else
const long long mod = 2000000000000021ll;
#endif

#ifdef LOCAL
typedef long long __int128_t;
#endif

struct Modint {
    long long x;
    Modint() {
        x = 0;
    }
    Modint(long long _x) {
        while (_x >= mod) {
            _x -= mod;
        }
        while (_x < 0) {
            _x += mod;
        }
        x = _x;
    }
    Modint(__int128_t _x) {
        if (_x >= mod || _x <= -mod) {
            _x %= mod;
        }
        if (_x < 0) {
            _x += mod;
        }
        x = _x;
    }
    Modint operator+(const Modint& other) const {
        return Modint(x + other.x);
    }
    Modint operator-(const Modint& other) const {
        return Modint(x - other.x);
    }
    Modint operator*(const Modint& other) const {
        return Modint((__int128_t)x * other.x);
    }
    void operator+=(const Modint& other) {
        *this = *this + other;
    }
    void operator-=(const Modint& other) {
        *this = *this - other;
    }
    void operator*=(const Modint& other) {
        *this = *this * other;
    }
    Modint operator^(long long k) const {
        Modint tmp = x, res = 1;
        while (k > 0) {
            // cerr << k << '\n';
            if (k & 1ll) {
                res *= tmp;
            }
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    ~Modint() {}
};

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    Modint denom = 1;
    for (int i = 0; i < n; ++i) {
        denom = denom + denom;
    }
    // cerr << denom.x << '\n';
    denom = (denom - 1) ^ (mod - 2);
    // cerr << (denom * ((1ll << n) - 1)).x << '\n';
    vector<long long> x(n);
    for (int i = 0; i < n; ++i) {
        Modint xmod = 0;
        for (int j = i; j >= 0; --j) {
            xmod = xmod + xmod + b[j] - a[j];
        }
        for (int j = n - 1; j > i; --j) {
            xmod = xmod + xmod + b[j] - a[j];
        }
        xmod = (Modint(0) - xmod) * denom;
        if (xmod.x > mod / 2) {
            cout << "No\n";
            return;
        }
        x[i] = xmod.x;
    }
    for (int i = 0, prv = n - 1; i < n; ++i, ++prv) {
        if (prv == n) { prv = 0; }
        if (x[prv] - 2 * x[i] != b[i] - a[i]) {
            cout << "No\n";
            return;
        }
    }
    bool change = true;
    while (change) {
        change = false;
        for (int i = 0; i < n; ++i) {
            if (x[i] > 0 && a[i] >= 2) {
                change = true;
                long long trans = min(x[i], a[i] * 1ll / 2);
                x[i] -= trans;
                a[i] -= 2 * trans;
                int nxt = i + 1;
                if (nxt == n) {
                    nxt = 0;
                }
                a[nxt] += trans;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (x[i] != 0) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        cerr << "-----------\n";
        cout << "-----------\n";
    }
#else
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
#endif

    return 0;
}

/*
2000000000000021
2000000000000077
2000000000000081
*/

Compilation message

remittance.cpp: In member function 'Modint Modint::operator^(long long int) const':
remittance.cpp:56:31: error: conversion from 'int' to 'Modint' is ambiguous
   56 |         Modint tmp = x, res = 1;
      |                               ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp: In function 'void solve()':
remittance.cpp:77:20: error: conversion from 'int' to 'Modint' is ambiguous
   77 |     Modint denom = 1;
      |                    ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:82:22: error: conversion from 'int' to 'const Modint' is ambiguous
   82 |     denom = (denom - 1) ^ (mod - 2);
      |                      ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:40:36: note:   initializing argument 1 of 'Modint Modint::operator-(const Modint&) const'
   40 |     Modint operator-(const Modint& other) const {
      |                      ~~~~~~~~~~~~~~^~~~~
remittance.cpp:86:23: error: conversion from 'int' to 'Modint' is ambiguous
   86 |         Modint xmod = 0;
      |                       ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:88:37: error: conversion from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const Modint' is ambiguous
   88 |             xmod = xmod + xmod + b[j] - a[j];
      |                                     ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:37:36: note:   initializing argument 1 of 'Modint Modint::operator+(const Modint&) const'
   37 |     Modint operator+(const Modint& other) const {
      |                      ~~~~~~~~~~~~~~^~~~~
remittance.cpp:91:37: error: conversion from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const Modint' is ambiguous
   91 |             xmod = xmod + xmod + b[j] - a[j];
      |                                     ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:37:36: note:   initializing argument 1 of 'Modint Modint::operator+(const Modint&) const'
   37 |     Modint operator+(const Modint& other) const {
      |                      ~~~~~~~~~~~~~~^~~~~
remittance.cpp:93:25: error: call of overloaded 'Modint(int)' is ambiguous
   93 |         xmod = (Modint(0) - xmod) * denom;
      |                         ^
remittance.cpp:28:5: note: candidate: 'Modint::Modint(__int128)'
   28 |     Modint(__int128_t _x) {
      |     ^~~~~~
remittance.cpp:19:5: note: candidate: 'Modint::Modint(long long int)'
   19 |     Modint(long long _x) {
      |     ^~~~~~
remittance.cpp:14:8: note: candidate: 'constexpr Modint::Modint(const Modint&)'
   14 | struct Modint {
      |        ^~~~~~