結果

問題 No.1306 Exactly 2 Digits
ユーザー 👑 hitonanodehitonanode
提出日時 2020-12-03 01:32:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,757 bytes
コンパイル時間 2,654 ms
コンパイル使用メモリ 221,564 KB
実行使用メモリ 24,408 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:46:57
合計ジャッジ時間 17,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,096 KB
testcase_01 AC 27 ms
24,036 KB
testcase_02 AC 27 ms
23,400 KB
testcase_03 AC 28 ms
23,976 KB
testcase_04 AC 27 ms
24,060 KB
testcase_05 AC 26 ms
23,664 KB
testcase_06 AC 28 ms
24,084 KB
testcase_07 AC 26 ms
23,448 KB
testcase_08 AC 28 ms
23,448 KB
testcase_09 AC 27 ms
24,348 KB
testcase_10 AC 27 ms
23,820 KB
testcase_11 AC 27 ms
24,036 KB
testcase_12 AC 27 ms
23,448 KB
testcase_13 AC 27 ms
23,568 KB
testcase_14 AC 28 ms
24,012 KB
testcase_15 AC 27 ms
24,036 KB
testcase_16 AC 26 ms
23,448 KB
testcase_17 AC 27 ms
23,460 KB
testcase_18 AC 27 ms
23,832 KB
testcase_19 AC 27 ms
24,048 KB
testcase_20 AC 27 ms
23,400 KB
testcase_21 AC 29 ms
24,336 KB
testcase_22 AC 27 ms
23,412 KB
testcase_23 AC 28 ms
23,532 KB
testcase_24 AC 27 ms
24,240 KB
testcase_25 AC 28 ms
23,856 KB
testcase_26 AC 28 ms
23,880 KB
testcase_27 AC 28 ms
23,376 KB
testcase_28 AC 27 ms
24,384 KB
testcase_29 AC 28 ms
23,676 KB
testcase_30 AC 27 ms
23,652 KB
testcase_31 AC 27 ms
23,376 KB
testcase_32 AC 27 ms
24,288 KB
testcase_33 AC 27 ms
23,532 KB
testcase_34 AC 27 ms
23,616 KB
testcase_35 AC 27 ms
23,868 KB
testcase_36 AC 27 ms
23,580 KB
testcase_37 AC 27 ms
24,036 KB
testcase_38 AC 28 ms
23,640 KB
testcase_39 AC 28 ms
23,688 KB
testcase_40 AC 28 ms
23,700 KB
testcase_41 AC 28 ms
23,628 KB
testcase_42 AC 28 ms
23,364 KB
testcase_43 AC 28 ms
24,396 KB
testcase_44 AC 29 ms
24,288 KB
testcase_45 AC 30 ms
24,060 KB
testcase_46 AC 30 ms
23,820 KB
testcase_47 AC 31 ms
23,412 KB
testcase_48 AC 32 ms
23,436 KB
testcase_49 AC 32 ms
23,400 KB
testcase_50 AC 33 ms
24,336 KB
testcase_51 AC 34 ms
24,096 KB
testcase_52 AC 36 ms
23,820 KB
testcase_53 AC 39 ms
24,048 KB
testcase_54 AC 37 ms
23,676 KB
testcase_55 AC 40 ms
24,096 KB
testcase_56 AC 42 ms
24,348 KB
testcase_57 AC 45 ms
24,324 KB
testcase_58 AC 45 ms
23,520 KB
testcase_59 AC 44 ms
23,520 KB
testcase_60 AC 53 ms
23,868 KB
testcase_61 AC 56 ms
23,352 KB
testcase_62 AC 55 ms
24,288 KB
testcase_63 AC 59 ms
23,376 KB
testcase_64 AC 57 ms
24,252 KB
testcase_65 AC 60 ms
24,060 KB
testcase_66 AC 65 ms
23,568 KB
testcase_67 AC 67 ms
24,072 KB
testcase_68 AC 68 ms
23,412 KB
testcase_69 AC 72 ms
23,436 KB
testcase_70 AC 72 ms
23,688 KB
testcase_71 AC 75 ms
23,364 KB
testcase_72 AC 74 ms
23,364 KB
testcase_73 AC 74 ms
24,096 KB
testcase_74 AC 84 ms
23,664 KB
testcase_75 AC 81 ms
23,364 KB
testcase_76 AC 93 ms
23,364 KB
testcase_77 AC 102 ms
24,036 KB
testcase_78 AC 103 ms
23,664 KB
testcase_79 AC 115 ms
24,048 KB
testcase_80 AC 111 ms
24,048 KB
testcase_81 AC 95 ms
23,352 KB
testcase_82 AC 116 ms
23,412 KB
testcase_83 AC 125 ms
23,400 KB
testcase_84 AC 126 ms
23,448 KB
testcase_85 AC 134 ms
23,424 KB
testcase_86 AC 114 ms
23,460 KB
testcase_87 AC 121 ms
23,508 KB
testcase_88 AC 143 ms
23,664 KB
testcase_89 AC 121 ms
24,072 KB
testcase_90 AC 108 ms
23,520 KB
testcase_91 AC 119 ms
24,036 KB
testcase_92 AC 111 ms
24,336 KB
testcase_93 AC 129 ms
23,364 KB
testcase_94 AC 112 ms
23,352 KB
testcase_95 AC 114 ms
24,312 KB
testcase_96 AC 107 ms
23,412 KB
testcase_97 AC 108 ms
23,364 KB
testcase_98 AC 99 ms
23,856 KB
testcase_99 AC 119 ms
23,364 KB
testcase_100 AC 117 ms
23,412 KB
testcase_101 AC 131 ms
24,060 KB
testcase_102 AC 110 ms
24,024 KB
testcase_103 AC 116 ms
23,376 KB
testcase_104 AC 114 ms
23,400 KB
testcase_105 AC 116 ms
24,348 KB
testcase_106 AC 105 ms
23,412 KB
testcase_107 AC 118 ms
23,448 KB
testcase_108 AC 115 ms
24,288 KB
testcase_109 AC 134 ms
23,664 KB
testcase_110 AC 109 ms
24,060 KB
testcase_111 AC 112 ms
23,400 KB
testcase_112 AC 103 ms
23,868 KB
testcase_113 AC 135 ms
23,460 KB
testcase_114 AC 139 ms
23,436 KB
testcase_115 AC 117 ms
24,408 KB
testcase_116 AC 145 ms
23,424 KB
testcase_117 AC 119 ms
23,376 KB
testcase_118 AC 129 ms
23,412 KB
testcase_119 AC 113 ms
24,024 KB
testcase_120 AC 107 ms
24,360 KB
testcase_121 AC 130 ms
23,640 KB
testcase_122 AC 126 ms
23,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }

pint query(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int x, y;
    cin >> x >> y;
    return make_pair(x, y);
}

pint simulate(pint pi, pint pj) {
    pint ret = pi - pj;
    if (ret.first > ret.second) swap(ret.first, ret.second);
    return ret;
}

int main()
{
    int N;
    cin >> N;
    const int L = N * N - N;

    map<int, int> freqcnt;
    freqcnt[0] += 2;
    map<pint, vector<int>> p2i;

    for (int i = 1; i < L; i++) {
        auto [x, y] = query(i, 0);
        p2i[pint(x, y)].emplace_back(i);
        if (x == 0 or y == 0) freqcnt[x + y]++;
    }

    const int lo = freqcnt.begin()->first;
    const int hi = prev(freqcnt.end())->first;
    int lo2 = lo, hi2 = hi;
    while (freqcnt[lo2] == 1) lo2++;
    while (freqcnt[hi2] == 1) hi2--;

    vector<pint> ret(L, pint(-1, -1));

    if (hi2 - lo == N - 1 and hi - lo2 == N - 2) {
        ret[0] = make_pair(-lo2 + 1, -lo); // (十, 一)
    } else if (hi2 - lo == N - 2 and hi - lo2 == N - 1) {
        ret[0] = make_pair(-lo + 1, -lo2);
    }

    auto is_valid = [&](pint p) -> bool { return p.first > 0 and p.first < N and p.second >= 0 and p.second < N; };

    vector<int> ics;
    for (const auto [p, is] : p2i) {
        pint pa = p;
        if (is.size() == 1) {
            int i = is[0];
            pint pcand = ret[0] + pa;
            if (is_valid(pcand)) ret[i] = pcand;
            else {
                swap(pa.first, pa.second);
                ret[i] = ret[0] + pa;
            }
            ics.emplace_back(i);
        }
    }
    assert(ics.size() > 0);

    for (const auto [p, is] : p2i) {
        if (is.size() == 2) {
            pint pa = p;
            const int i = is[0], j = is[1];

            const pint p1 = ret[0] + pa;
            swap(pa.first, pa.second);
            const pint p2 = ret[0] + pa;

            for (auto ic : ics) {
                pint psim1 = simulate(p1, ret[ic]);
                pint psim2 = simulate(p2, ret[ic]);
                if (psim1 != psim2) {
                    pint ptmp = query(i, ic);
                    if (psim1 == ptmp) ret[i] = p1, ret[j] = p2;
                    else ret[i] = p2, ret[j] = p1;
                    break;
                }
            }
        }
    }
    cout << "! ";
    for (auto x : ret) cout << x.first * N + x.second << ' ';
    cout << endl;
}
0