結果

問題 No.1306 Exactly 2 Digits
ユーザー やむなくやむなく
提出日時 2020-12-03 02:11:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 787 ms / 2,000 ms
コード長 4,197 bytes
コンパイル時間 2,915 ms
コンパイル使用メモリ 219,272 KB
実行使用メモリ 24,372 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:56:05
合計ジャッジ時間 43,564 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,168 KB
testcase_01 AC 24 ms
24,336 KB
testcase_02 AC 24 ms
24,276 KB
testcase_03 AC 26 ms
23,760 KB
testcase_04 AC 25 ms
24,048 KB
testcase_05 AC 25 ms
23,532 KB
testcase_06 AC 24 ms
24,288 KB
testcase_07 AC 25 ms
23,388 KB
testcase_08 AC 25 ms
23,580 KB
testcase_09 AC 25 ms
24,288 KB
testcase_10 AC 25 ms
23,556 KB
testcase_11 AC 25 ms
23,604 KB
testcase_12 AC 25 ms
23,376 KB
testcase_13 AC 25 ms
23,460 KB
testcase_14 AC 26 ms
23,364 KB
testcase_15 AC 25 ms
23,640 KB
testcase_16 AC 25 ms
23,376 KB
testcase_17 AC 25 ms
24,180 KB
testcase_18 AC 25 ms
23,376 KB
testcase_19 AC 25 ms
23,292 KB
testcase_20 AC 25 ms
23,280 KB
testcase_21 AC 25 ms
23,328 KB
testcase_22 AC 25 ms
23,448 KB
testcase_23 AC 25 ms
23,736 KB
testcase_24 AC 26 ms
23,364 KB
testcase_25 AC 25 ms
23,364 KB
testcase_26 AC 26 ms
23,820 KB
testcase_27 AC 26 ms
23,616 KB
testcase_28 AC 26 ms
23,964 KB
testcase_29 AC 25 ms
24,276 KB
testcase_30 AC 26 ms
23,412 KB
testcase_31 AC 26 ms
23,916 KB
testcase_32 AC 25 ms
23,448 KB
testcase_33 AC 25 ms
23,412 KB
testcase_34 AC 26 ms
23,976 KB
testcase_35 AC 26 ms
23,520 KB
testcase_36 AC 25 ms
24,264 KB
testcase_37 AC 25 ms
24,372 KB
testcase_38 AC 26 ms
23,748 KB
testcase_39 AC 26 ms
23,640 KB
testcase_40 AC 26 ms
23,412 KB
testcase_41 AC 26 ms
23,628 KB
testcase_42 AC 25 ms
23,556 KB
testcase_43 AC 26 ms
23,760 KB
testcase_44 AC 27 ms
23,940 KB
testcase_45 AC 28 ms
23,964 KB
testcase_46 AC 29 ms
24,288 KB
testcase_47 AC 30 ms
23,520 KB
testcase_48 AC 32 ms
23,520 KB
testcase_49 AC 32 ms
23,388 KB
testcase_50 AC 34 ms
23,328 KB
testcase_51 AC 36 ms
24,276 KB
testcase_52 AC 40 ms
23,436 KB
testcase_53 AC 43 ms
24,300 KB
testcase_54 AC 43 ms
23,820 KB
testcase_55 AC 49 ms
24,048 KB
testcase_56 AC 53 ms
24,168 KB
testcase_57 AC 55 ms
24,060 KB
testcase_58 AC 63 ms
24,372 KB
testcase_59 AC 66 ms
23,364 KB
testcase_60 AC 77 ms
23,964 KB
testcase_61 AC 85 ms
23,916 KB
testcase_62 AC 93 ms
23,616 KB
testcase_63 AC 103 ms
23,448 KB
testcase_64 AC 108 ms
23,940 KB
testcase_65 AC 118 ms
23,928 KB
testcase_66 AC 135 ms
23,808 KB
testcase_67 AC 147 ms
24,264 KB
testcase_68 AC 156 ms
23,652 KB
testcase_69 AC 174 ms
24,300 KB
testcase_70 AC 191 ms
23,292 KB
testcase_71 AC 207 ms
24,036 KB
testcase_72 AC 231 ms
23,340 KB
testcase_73 AC 248 ms
23,364 KB
testcase_74 AC 275 ms
23,412 KB
testcase_75 AC 295 ms
24,048 KB
testcase_76 AC 329 ms
23,964 KB
testcase_77 AC 368 ms
23,460 KB
testcase_78 AC 391 ms
23,292 KB
testcase_79 AC 440 ms
23,568 KB
testcase_80 AC 473 ms
23,820 KB
testcase_81 AC 491 ms
24,276 KB
testcase_82 AC 560 ms
23,412 KB
testcase_83 AC 649 ms
23,736 KB
testcase_84 AC 660 ms
23,532 KB
testcase_85 AC 757 ms
24,288 KB
testcase_86 AC 628 ms
23,916 KB
testcase_87 AC 684 ms
23,460 KB
testcase_88 AC 773 ms
23,148 KB
testcase_89 AC 653 ms
24,264 KB
testcase_90 AC 749 ms
24,276 KB
testcase_91 AC 594 ms
24,012 KB
testcase_92 AC 687 ms
23,604 KB
testcase_93 AC 655 ms
23,520 KB
testcase_94 AC 584 ms
23,616 KB
testcase_95 AC 628 ms
24,048 KB
testcase_96 AC 580 ms
24,300 KB
testcase_97 AC 681 ms
23,544 KB
testcase_98 AC 587 ms
23,412 KB
testcase_99 AC 596 ms
23,520 KB
testcase_100 AC 602 ms
23,640 KB
testcase_101 AC 640 ms
24,264 KB
testcase_102 AC 580 ms
23,328 KB
testcase_103 AC 600 ms
23,916 KB
testcase_104 AC 633 ms
23,364 KB
testcase_105 AC 743 ms
23,364 KB
testcase_106 AC 619 ms
23,748 KB
testcase_107 AC 748 ms
23,412 KB
testcase_108 AC 731 ms
23,280 KB
testcase_109 AC 762 ms
23,376 KB
testcase_110 AC 627 ms
23,820 KB
testcase_111 AC 743 ms
24,300 KB
testcase_112 AC 589 ms
24,180 KB
testcase_113 AC 759 ms
23,292 KB
testcase_114 AC 720 ms
24,288 KB
testcase_115 AC 685 ms
23,928 KB
testcase_116 AC 787 ms
23,532 KB
testcase_117 AC 696 ms
24,276 KB
testcase_118 AC 747 ms
23,556 KB
testcase_119 AC 731 ms
23,748 KB
testcase_120 AC 635 ms
24,036 KB
testcase_121 AC 648 ms
24,024 KB
testcase_122 AC 636 ms
23,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2020/12/03.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

pair<int, int> query(int i, int j) {
    cout << "?" SP i + 1 SP j + 1 << endl;
    int p, q;
    cin >> p >> q;
    return {p, q};
}

int main() {
    //CFS;
    int n;
    cin >> n;
    map<pair<int, int>, vector<int>> mp;
    repl(i, 1, n * n - n) {
        auto p = query(i, 0);
        mp[p].push_back(i);
    }
    int pi = -1, pj = -1;
    rep(i, n - 1) {
        rep(j, n) {
            map<pair<int, int>, int> sz;
            rep(k, n - 1) {
                rep(l, n) {
                    if (i != k || j != l) {
                        int p = k - i, q = l - j;
                        if (p > q) swap(p, q);
                        sz[{p, q}]++;
                    }
                }
            }
            auto itr = sz.begin();
            auto itr2 = mp.begin();
            for (; itr != sz.end(); itr++, itr2++) {
                if (itr2->first != itr->first || itr2->second.size() != itr->second) goto next;
            }
            pi = i, pj = j;
            next:;
        }
    }
    mti ans(n - 1, vi(n, -1));
    ans[pi][pj] = 0;
    auto pl = mp.begin()->first;
    if (pl.first != pl.second && (pi != 0 || pj != 0)) {
        int l = mp.begin()->second[0];
        for (auto &c : mp) {
            int nx = pi + c.first.first, ny = pj + c.first.second;
            if (c.second.size() == 1) {
                if (nx < 0 || n - 1 <= nx || ny < 0 || n <= ny) {
                    nx = pi + c.first.second, ny = pj + c.first.first;
                }
                ans[nx][ny] = c.second[0];
            } else {
                auto s = query(c.second[0], l);
                if (nx == s.first && ny == s.second || nx == s.second && ny == s.first) {
                    ans[nx][ny] = c.second[0];
                    ans[pi + c.first.second][pj + c.first.first] = c.second[1];
                } else {
                    ans[nx][ny] = c.second[1];
                    ans[pi + c.first.second][pj + c.first.first] = c.second[0];
                }
            }
        }
    } else {
        int r = mp.rbegin()->second[0];
        for (auto &c : mp) {
            int nx = pi + c.first.first, ny = pj + c.first.second;
            if (c.second.size() == 1) {
                if (nx < 0 || n - 1 <= nx || ny < 0 || n <= ny) {
                    nx = pi + c.first.second, ny = pj + c.first.first;
                }
                ans[nx][ny] = c.second[0];
            } else {
                auto s = query(c.second[0], r);
                if (nx == s.first + n - 2 && ny == s.second + n - 1 || nx == s.second + n - 2 && ny == s.first + n - 1) {
                    ans[nx][ny] = c.second[0];
                    ans[pi + c.first.second][pj + c.first.first] = c.second[1];
                } else {
                    ans[nx][ny] = c.second[1];
                    ans[pi + c.first.second][pj + c.first.first] = c.second[0];
                }
            }
        }
    }
//    rep(i, n - 1) {
//        rep(j, n) {
//            cout << ans[i][j] << " ";
//        }
//        cout << endl;
//    }
    vi ansp(n * n - n);
    rep(i, n - 1) rep(j, n) ansp[ans[i][j]] = i * n + j + n;
    cout << "!";
    for (auto &x : ansp) cout << " " << x;
    cout << endl;
    return 0;
}
0