結果

問題 No.2828 Remainder Game
ユーザー ATMATM
提出日時 2024-08-02 22:35:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,841 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 173,448 KB
実行使用メモリ 25,464 KB
平均クエリ数 58.00
最終ジャッジ日時 2024-08-02 22:35:18
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 63 ms
24,940 KB
testcase_05 WA -
testcase_06 AC 64 ms
24,952 KB
testcase_07 AC 67 ms
25,464 KB
testcase_08 AC 66 ms
24,824 KB
testcase_09 WA -
testcase_10 AC 65 ms
25,208 KB
testcase_11 AC 66 ms
25,196 KB
testcase_12 AC 65 ms
25,208 KB
testcase_13 AC 88 ms
24,952 KB
testcase_14 AC 65 ms
25,192 KB
testcase_15 AC 66 ms
24,952 KB
testcase_16 AC 66 ms
25,464 KB
testcase_17 AC 64 ms
24,824 KB
testcase_18 AC 66 ms
24,824 KB
testcase_19 AC 64 ms
24,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 998244353LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

#define F first
#define S second

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define all(x) (x).begin(), (x).end()
#define ll long long int
#define VI vector<ll>
#define VVI vector<VI>

#define ISD true
#define debug(x) \
    if (ISD)     \
    cout << #x << ": " << x << endl

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}

inline long long mod(long long a, long long m)
{
    return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q)
{
    if (b == 0)
    {
        p = 1;
        q = 0;
        return a;
    }
    long long d = extGcd(b, a % b, q, p);
    q -= a / b * p;
    return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(const vector<long long> &b, const vector<long long> &m)
{
    long long r = 0, M = 1;
    for (int i = 0; i < (int)b.size(); ++i)
    {
        long long p, q;
        long long d = extGcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d)
        if ((b[i] - r) % d != 0)
            return make_pair(0, -1);
        long long tmp = (b[i] - r) / d * p % (m[i] / d);
        r += M * tmp;
        M *= m[i] / d;
    }
    return make_pair(mod(r, M), M);
}

int main()
{
    int N;
    cin >> N;
    vector<int> c = {2, 3, 5, 7, 11};
    vector<ll> b, m;
    REP(i, 5)
    {
        int sum = 0;
        REP(j, c[i])
        {
            cout << c[i] << " " << 1 << endl;
            cout << j << endl;
            int s;
            cin >> s;
            sum += (s * j) % c[i];
        }
        b.push_back(sum);
        m.push_back(c[i]);
    }
    auto t = ChineseRem(b, m);
    cout << "0 1" << endl;
    cout << t.F << endl;
}
0