結果

問題 No.1306 Exactly 2 Digits
ユーザー やむなくやむなく
提出日時 2020-12-03 02:02:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,205 bytes
コンパイル時間 2,922 ms
コンパイル使用メモリ 220,308 KB
実行使用メモリ 24,384 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:53:42
合計ジャッジ時間 44,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,628 KB
testcase_01 WA -
testcase_02 AC 27 ms
24,360 KB
testcase_03 AC 25 ms
24,048 KB
testcase_04 AC 26 ms
24,048 KB
testcase_05 AC 25 ms
24,036 KB
testcase_06 AC 26 ms
23,616 KB
testcase_07 AC 25 ms
24,024 KB
testcase_08 AC 25 ms
24,276 KB
testcase_09 AC 27 ms
23,412 KB
testcase_10 AC 26 ms
24,360 KB
testcase_11 AC 26 ms
24,036 KB
testcase_12 AC 26 ms
23,652 KB
testcase_13 AC 26 ms
24,288 KB
testcase_14 AC 26 ms
23,604 KB
testcase_15 AC 28 ms
24,024 KB
testcase_16 AC 26 ms
24,000 KB
testcase_17 AC 27 ms
24,096 KB
testcase_18 AC 26 ms
23,364 KB
testcase_19 AC 26 ms
24,372 KB
testcase_20 AC 26 ms
23,568 KB
testcase_21 AC 26 ms
23,364 KB
testcase_22 AC 26 ms
23,232 KB
testcase_23 AC 27 ms
23,616 KB
testcase_24 AC 26 ms
24,036 KB
testcase_25 AC 26 ms
23,640 KB
testcase_26 AC 26 ms
23,448 KB
testcase_27 AC 27 ms
24,264 KB
testcase_28 AC 26 ms
23,832 KB
testcase_29 AC 26 ms
23,400 KB
testcase_30 AC 26 ms
23,568 KB
testcase_31 AC 27 ms
24,096 KB
testcase_32 WA -
testcase_33 AC 27 ms
23,280 KB
testcase_34 AC 27 ms
23,400 KB
testcase_35 AC 27 ms
23,400 KB
testcase_36 AC 27 ms
24,048 KB
testcase_37 AC 27 ms
23,832 KB
testcase_38 WA -
testcase_39 AC 27 ms
23,448 KB
testcase_40 AC 27 ms
24,276 KB
testcase_41 AC 27 ms
24,264 KB
testcase_42 AC 27 ms
23,580 KB
testcase_43 AC 29 ms
23,460 KB
testcase_44 AC 29 ms
23,568 KB
testcase_45 AC 30 ms
24,336 KB
testcase_46 AC 30 ms
23,544 KB
testcase_47 AC 31 ms
23,628 KB
testcase_48 AC 34 ms
23,676 KB
testcase_49 AC 34 ms
23,604 KB
testcase_50 AC 36 ms
24,048 KB
testcase_51 AC 37 ms
23,832 KB
testcase_52 AC 41 ms
24,036 KB
testcase_53 AC 45 ms
23,568 KB
testcase_54 AC 44 ms
23,688 KB
testcase_55 AC 50 ms
24,048 KB
testcase_56 AC 54 ms
23,688 KB
testcase_57 AC 58 ms
24,048 KB
testcase_58 AC 63 ms
24,276 KB
testcase_59 AC 66 ms
23,532 KB
testcase_60 AC 78 ms
23,364 KB
testcase_61 AC 87 ms
23,460 KB
testcase_62 AC 93 ms
23,436 KB
testcase_63 AC 103 ms
23,628 KB
testcase_64 AC 110 ms
23,616 KB
testcase_65 AC 119 ms
23,580 KB
testcase_66 AC 135 ms
24,036 KB
testcase_67 AC 147 ms
24,048 KB
testcase_68 AC 158 ms
23,532 KB
testcase_69 AC 177 ms
24,324 KB
testcase_70 AC 193 ms
23,556 KB
testcase_71 AC 213 ms
23,388 KB
testcase_72 AC 231 ms
23,364 KB
testcase_73 AC 250 ms
23,352 KB
testcase_74 AC 281 ms
23,364 KB
testcase_75 AC 298 ms
24,048 KB
testcase_76 AC 330 ms
24,348 KB
testcase_77 AC 369 ms
23,664 KB
testcase_78 AC 399 ms
24,024 KB
testcase_79 AC 445 ms
23,220 KB
testcase_80 AC 475 ms
24,036 KB
testcase_81 AC 497 ms
24,084 KB
testcase_82 AC 564 ms
24,048 KB
testcase_83 AC 650 ms
23,364 KB
testcase_84 AC 660 ms
23,688 KB
testcase_85 AC 763 ms
24,012 KB
testcase_86 AC 643 ms
24,276 KB
testcase_87 AC 690 ms
24,360 KB
testcase_88 AC 784 ms
23,616 KB
testcase_89 AC 648 ms
23,688 KB
testcase_90 AC 747 ms
24,036 KB
testcase_91 AC 595 ms
23,868 KB
testcase_92 AC 692 ms
23,448 KB
testcase_93 AC 654 ms
24,384 KB
testcase_94 AC 584 ms
24,276 KB
testcase_95 AC 634 ms
24,048 KB
testcase_96 AC 583 ms
23,400 KB
testcase_97 AC 689 ms
23,832 KB
testcase_98 AC 590 ms
23,664 KB
testcase_99 AC 595 ms
24,360 KB
testcase_100 AC 605 ms
23,880 KB
testcase_101 AC 648 ms
23,880 KB
testcase_102 AC 584 ms
23,412 KB
testcase_103 AC 600 ms
23,688 KB
testcase_104 AC 637 ms
24,012 KB
testcase_105 AC 744 ms
24,048 KB
testcase_106 AC 621 ms
24,360 KB
testcase_107 AC 752 ms
23,520 KB
testcase_108 AC 740 ms
24,348 KB
testcase_109 AC 771 ms
23,412 KB
testcase_110 AC 629 ms
24,360 KB
testcase_111 AC 756 ms
23,568 KB
testcase_112 AC 589 ms
24,336 KB
testcase_113 AC 761 ms
24,336 KB
testcase_114 AC 723 ms
23,616 KB
testcase_115 AC 700 ms
23,820 KB
testcase_116 AC 781 ms
23,616 KB
testcase_117 AC 707 ms
24,324 KB
testcase_118 AC 751 ms
24,024 KB
testcase_119 AC 741 ms
23,460 KB
testcase_120 AC 637 ms
23,400 KB
testcase_121 AC 658 ms
23,400 KB
testcase_122 AC 641 ms
24,360 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;
//    cout << pi SP pj << endl;
    auto pl = mp.begin()->first;
    if (pl.first != pl.second) {
        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