結果

問題 No.1306 Exactly 2 Digits
ユーザー chocoruskchocorusk
提出日時 2020-12-03 01:46:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,829 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 147,952 KB
実行使用メモリ 24,432 KB
平均クエリ数 1018.15
最終ジャッジ日時 2023-09-24 07:50:53
合計ジャッジ時間 60,949 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,412 KB
testcase_01 RE -
testcase_02 AC 26 ms
23,400 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 25 ms
23,760 KB
testcase_07 AC 25 ms
23,364 KB
testcase_08 AC 25 ms
23,616 KB
testcase_09 AC 26 ms
23,376 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 25 ms
24,276 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 27 ms
24,252 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
testcase_94 RE -
testcase_95 RE -
testcase_96 RE -
testcase_97 RE -
testcase_98 RE -
testcase_99 RE -
testcase_100 RE -
testcase_101 RE -
testcase_102 RE -
testcase_103 RE -
testcase_104 RE -
testcase_105 RE -
testcase_106 RE -
testcase_107 RE -
testcase_108 RE -
testcase_109 RE -
testcase_110 RE -
testcase_111 RE -
testcase_112 RE -
testcase_113 RE -
testcase_114 RE -
testcase_115 RE -
testcase_116 RE -
testcase_117 RE -
testcase_118 RE -
testcase_119 RE -
testcase_120 RE -
testcase_121 RE -
testcase_122 RE -
権限があれば一括ダウンロードができます

ソースコード

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.find(P(v[i].second, v[i].first))==mp.end()){
            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[P(v[i].second, v[i].first)];
        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