結果

問題 No.1306 Exactly 2 Digits
ユーザー chocoruskchocorusk
提出日時 2020-12-03 02:03:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 3,773 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 146,092 KB
実行使用メモリ 24,480 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:52:57
合計ジャッジ時間 31,546 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,048 KB
testcase_01 AC 26 ms
24,012 KB
testcase_02 AC 26 ms
24,048 KB
testcase_03 AC 27 ms
23,520 KB
testcase_04 AC 27 ms
23,652 KB
testcase_05 AC 27 ms
24,384 KB
testcase_06 AC 27 ms
24,024 KB
testcase_07 AC 27 ms
23,520 KB
testcase_08 AC 27 ms
23,364 KB
testcase_09 AC 26 ms
23,364 KB
testcase_10 AC 27 ms
23,652 KB
testcase_11 AC 26 ms
23,628 KB
testcase_12 AC 26 ms
23,616 KB
testcase_13 AC 26 ms
23,376 KB
testcase_14 AC 27 ms
24,144 KB
testcase_15 AC 26 ms
23,400 KB
testcase_16 AC 27 ms
24,036 KB
testcase_17 AC 26 ms
23,352 KB
testcase_18 AC 26 ms
23,640 KB
testcase_19 AC 26 ms
23,364 KB
testcase_20 AC 26 ms
24,324 KB
testcase_21 AC 26 ms
24,324 KB
testcase_22 AC 26 ms
23,640 KB
testcase_23 AC 27 ms
24,036 KB
testcase_24 AC 26 ms
23,364 KB
testcase_25 AC 26 ms
24,036 KB
testcase_26 AC 27 ms
24,024 KB
testcase_27 AC 28 ms
24,252 KB
testcase_28 AC 28 ms
23,652 KB
testcase_29 AC 27 ms
23,808 KB
testcase_30 AC 27 ms
24,012 KB
testcase_31 AC 27 ms
23,676 KB
testcase_32 AC 27 ms
23,532 KB
testcase_33 AC 27 ms
24,048 KB
testcase_34 AC 27 ms
23,520 KB
testcase_35 AC 26 ms
23,652 KB
testcase_36 AC 28 ms
23,508 KB
testcase_37 AC 28 ms
23,520 KB
testcase_38 AC 27 ms
23,628 KB
testcase_39 AC 27 ms
23,400 KB
testcase_40 AC 28 ms
23,364 KB
testcase_41 AC 28 ms
23,352 KB
testcase_42 AC 27 ms
23,352 KB
testcase_43 AC 27 ms
24,312 KB
testcase_44 AC 29 ms
24,024 KB
testcase_45 AC 30 ms
23,364 KB
testcase_46 AC 31 ms
24,024 KB
testcase_47 AC 32 ms
23,820 KB
testcase_48 AC 33 ms
23,616 KB
testcase_49 AC 34 ms
24,252 KB
testcase_50 AC 36 ms
24,036 KB
testcase_51 AC 36 ms
23,508 KB
testcase_52 AC 38 ms
23,640 KB
testcase_53 AC 44 ms
23,616 KB
testcase_54 AC 41 ms
23,376 KB
testcase_55 AC 45 ms
23,376 KB
testcase_56 AC 49 ms
23,532 KB
testcase_57 AC 52 ms
23,832 KB
testcase_58 AC 56 ms
23,364 KB
testcase_59 AC 59 ms
23,532 KB
testcase_60 AC 68 ms
23,640 KB
testcase_61 AC 75 ms
23,364 KB
testcase_62 AC 78 ms
23,616 KB
testcase_63 AC 85 ms
24,480 KB
testcase_64 AC 88 ms
24,036 KB
testcase_65 AC 95 ms
24,036 KB
testcase_66 AC 106 ms
24,048 KB
testcase_67 AC 114 ms
23,520 KB
testcase_68 AC 121 ms
23,520 KB
testcase_69 AC 130 ms
23,520 KB
testcase_70 AC 141 ms
24,036 KB
testcase_71 AC 154 ms
23,520 KB
testcase_72 AC 164 ms
23,628 KB
testcase_73 AC 172 ms
23,400 KB
testcase_74 AC 195 ms
23,364 KB
testcase_75 AC 207 ms
23,640 KB
testcase_76 AC 232 ms
23,520 KB
testcase_77 AC 253 ms
24,024 KB
testcase_78 AC 278 ms
24,048 KB
testcase_79 AC 303 ms
23,628 KB
testcase_80 AC 325 ms
23,520 KB
testcase_81 AC 328 ms
23,820 KB
testcase_82 AC 373 ms
23,616 KB
testcase_83 AC 426 ms
23,628 KB
testcase_84 AC 435 ms
24,036 KB
testcase_85 AC 495 ms
24,252 KB
testcase_86 AC 417 ms
24,036 KB
testcase_87 AC 448 ms
23,412 KB
testcase_88 AC 504 ms
24,372 KB
testcase_89 AC 423 ms
24,372 KB
testcase_90 AC 465 ms
24,048 KB
testcase_91 AC 398 ms
23,820 KB
testcase_92 AC 438 ms
23,808 KB
testcase_93 AC 431 ms
23,352 KB
testcase_94 AC 388 ms
23,652 KB
testcase_95 AC 420 ms
24,348 KB
testcase_96 AC 385 ms
23,640 KB
testcase_97 AC 435 ms
23,400 KB
testcase_98 AC 377 ms
24,324 KB
testcase_99 AC 399 ms
24,036 KB
testcase_100 AC 398 ms
23,400 KB
testcase_101 AC 434 ms
23,532 KB
testcase_102 AC 389 ms
23,400 KB
testcase_103 AC 398 ms
23,520 KB
testcase_104 AC 422 ms
23,652 KB
testcase_105 AC 477 ms
23,820 KB
testcase_106 AC 407 ms
23,376 KB
testcase_107 AC 474 ms
24,372 KB
testcase_108 AC 463 ms
23,652 KB
testcase_109 AC 491 ms
24,360 KB
testcase_110 AC 411 ms
24,264 KB
testcase_111 AC 471 ms
24,348 KB
testcase_112 AC 377 ms
23,364 KB
testcase_113 AC 496 ms
24,408 KB
testcase_114 AC 466 ms
24,264 KB
testcase_115 AC 447 ms
23,520 KB
testcase_116 AC 497 ms
24,384 KB
testcase_117 AC 450 ms
23,640 KB
testcase_118 AC 481 ms
23,628 KB
testcase_119 AC 471 ms
23,640 KB
testcase_120 AC 408 ms
23,520 KB
testcase_121 AC 427 ms
23,400 KB
testcase_122 AC 423 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    vector<P> v(n*n-n);
    for(int i=1; i<n*n-n; i++){
        cout<<"? 1 "<<i+1<<endl;
        int p, q;
        cin>>p>>q;
        v[i]=P(p, q);
    }
    vector<P> vs=v;
    sort(vs.begin(), vs.end());
    int a0=-1, b0=-1;
    for(int i=1; i<n; i++){
        for(int j=0; j<n; j++){
            vector<P> w(n*n-n);
            int k=0;
            for(int a=1; a<n; a++){
                for(int b=0; b<n; b++){
                    int p=i-a, q=j-b;
                    if(p>q) swap(p, q);
                    w[k++]=P(p, q);
                }
            }
            sort(w.begin(), w.end());
            bool dame=0;
            for(int a=0; a<n*n-n; a++){
                if(w[a]!=vs[a]){
                    dame=1;break;
                }
            }
            if(!dame){
                assert(a0==-1);
                a0=i, b0=j;
            }
        }
    }
    assert(a0!=-1);
    auto check=[&](int x, int y){
        if(x<1 || x>=n || y<0 || y>=n) return false;
        return true;
    };
    int ans[3000];
    fill(ans, ans+n*n-n, -1);
    ans[0]=a0*n+b0;
    map<P, int> mp;
    for(int i=1; i<n*n-n; i++) mp[v[i]]=i;
    int imn=0, imx=0;
    for(int i=1; i<n*n-n; i++){
        if(v[i].first+v[i].second<v[imx].first+v[imx].second) imx=i;
        if(v[i].first+v[i].second>v[imn].first+v[imn].second) imn=i;
    }
    ans[imx]=n*n-1, ans[imn]=n;
    for(int i=1; i<n*n-n; i++){
        if(v[i].first==v[i].second){
            ans[i]=(a0-v[i].first)*n+(b0-v[i].second);
            continue;
        }
        if(ans[i]!=-1) continue;
        if(mp[v[i]]==i){
            if(check(a0-v[i].first, b0-v[i].second)) ans[i]=(a0-v[i].first)*n+(b0-v[i].second);
            else ans[i]=(a0-v[i].second)*n+(b0-v[i].first);
            continue;
        }
        int j=mp[v[i]];
        int p1=a0-v[i].first-1, q1=b0-v[i].second, p2=a0-v[i].second-1, q2=b0-v[i].first;
        if(p1>q1) swap(p1, q1);
        if(p2>q2) swap(p2, q2);
        if(p1!=p2 || q1!=q2){
            cout<<"? "<<i+1<<" "<<imn+1<<endl;
            int p, q; cin>>p>>q;
            ans[i]=(a0-v[i].first)*n+(b0-v[i].second);
            ans[j]=(a0-v[i].second)*n+(b0-v[i].first);
            if(p==p2 && q==q2){
                swap(ans[i], ans[j]);
            }else if(p!=p1 || q!=q1){
                assert(0);
            }
        }else{
            p1=a0-v[i].first-(n-1), q1=b0-v[i].second-(n-1), p2=a0-v[i].second-(n-1), q2=b0-v[i].first-(n-1);
            if(p1>q1) swap(p1, q1);
            if(p2>q2) swap(p2, q2);
            assert(p1!=p2 || q1!=q2);
            cout<<"? "<<i+1<<" "<<imx+1<<endl;
            int p, q; cin>>p>>q;
            ans[i]=(a0-v[i].first)*n+(b0-v[i].second);
            ans[j]=(a0-v[i].second)*n+(b0-v[i].first);
            if(p==p2 && q==q2){
                swap(ans[i], ans[j]);
            }else if(p!=p1 || q!=q1){
                assert(0);
            }
        }
    }
    int ans1[3030];
    for(int i=0; i<n*n-n; i++) ans1[i]=ans[i];
    sort(ans1, ans1+n*n-n);
    for(int i=0; i<n*n-n; i++){
        assert(ans1[i]==n+i);
    }
    cout<<"!";
    for(int i=0; i<n*n-n; i++){
        cout<<" "<<ans[i];
    }
    cout<<endl;
    return 0;
}
0