結果

問題 No.1306 Exactly 2 Digits
ユーザー butsurizukibutsurizuki
提出日時 2020-11-09 00:27:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,436 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 216,148 KB
実行使用メモリ 24,372 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:03:05
合計ジャッジ時間 19,954 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,204 KB
testcase_01 WA -
testcase_02 AC 26 ms
24,180 KB
testcase_03 AC 26 ms
23,400 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 25 ms
24,192 KB
testcase_07 AC 25 ms
24,036 KB
testcase_08 AC 25 ms
23,376 KB
testcase_09 AC 27 ms
23,352 KB
testcase_10 AC 26 ms
23,640 KB
testcase_11 AC 25 ms
23,616 KB
testcase_12 AC 26 ms
23,796 KB
testcase_13 AC 26 ms
23,376 KB
testcase_14 AC 26 ms
23,364 KB
testcase_15 AC 27 ms
23,640 KB
testcase_16 AC 26 ms
23,604 KB
testcase_17 AC 26 ms
23,376 KB
testcase_18 AC 26 ms
23,232 KB
testcase_19 AC 26 ms
23,496 KB
testcase_20 AC 26 ms
23,616 KB
testcase_21 AC 26 ms
24,012 KB
testcase_22 AC 25 ms
24,240 KB
testcase_23 AC 26 ms
23,508 KB
testcase_24 AC 26 ms
23,928 KB
testcase_25 AC 26 ms
24,012 KB
testcase_26 AC 26 ms
24,300 KB
testcase_27 WA -
testcase_28 AC 27 ms
23,652 KB
testcase_29 AC 27 ms
24,012 KB
testcase_30 AC 27 ms
24,264 KB
testcase_31 AC 27 ms
23,352 KB
testcase_32 AC 27 ms
23,616 KB
testcase_33 AC 28 ms
23,496 KB
testcase_34 AC 27 ms
24,228 KB
testcase_35 AC 28 ms
23,688 KB
testcase_36 AC 27 ms
23,400 KB
testcase_37 AC 28 ms
23,640 KB
testcase_38 WA -
testcase_39 AC 27 ms
23,604 KB
testcase_40 AC 28 ms
24,180 KB
testcase_41 AC 27 ms
23,796 KB
testcase_42 AC 27 ms
23,496 KB
testcase_43 AC 27 ms
23,364 KB
testcase_44 AC 28 ms
23,400 KB
testcase_45 AC 28 ms
23,832 KB
testcase_46 AC 29 ms
23,940 KB
testcase_47 AC 30 ms
23,928 KB
testcase_48 AC 32 ms
24,180 KB
testcase_49 AC 31 ms
23,640 KB
testcase_50 AC 33 ms
24,024 KB
testcase_51 AC 34 ms
23,616 KB
testcase_52 AC 36 ms
23,364 KB
testcase_53 AC 39 ms
23,820 KB
testcase_54 AC 36 ms
23,952 KB
testcase_55 AC 40 ms
23,376 KB
testcase_56 AC 42 ms
24,168 KB
testcase_57 AC 43 ms
23,940 KB
testcase_58 AC 45 ms
23,628 KB
testcase_59 AC 44 ms
23,616 KB
testcase_60 AC 52 ms
24,012 KB
testcase_61 AC 55 ms
23,364 KB
testcase_62 AC 53 ms
23,592 KB
testcase_63 AC 58 ms
23,952 KB
testcase_64 AC 56 ms
23,616 KB
testcase_65 AC 58 ms
23,352 KB
testcase_66 AC 66 ms
24,252 KB
testcase_67 AC 66 ms
23,412 KB
testcase_68 AC 65 ms
23,640 KB
testcase_69 AC 70 ms
23,508 KB
testcase_70 AC 73 ms
24,180 KB
testcase_71 AC 75 ms
23,820 KB
testcase_72 AC 77 ms
23,364 KB
testcase_73 AC 71 ms
23,940 KB
testcase_74 AC 85 ms
23,616 KB
testcase_75 AC 80 ms
23,988 KB
testcase_76 AC 91 ms
23,784 KB
testcase_77 AC 97 ms
24,012 KB
testcase_78 WA -
testcase_79 AC 110 ms
24,144 KB
testcase_80 AC 115 ms
23,592 KB
testcase_81 AC 93 ms
23,820 KB
testcase_82 AC 119 ms
23,928 KB
testcase_83 AC 116 ms
23,616 KB
testcase_84 WA -
testcase_85 WA -
testcase_86 AC 110 ms
23,496 KB
testcase_87 AC 120 ms
23,364 KB
testcase_88 AC 145 ms
24,216 KB
testcase_89 AC 121 ms
24,036 KB
testcase_90 AC 104 ms
23,940 KB
testcase_91 AC 113 ms
23,328 KB
testcase_92 AC 110 ms
23,592 KB
testcase_93 AC 126 ms
24,132 KB
testcase_94 AC 108 ms
23,616 KB
testcase_95 AC 116 ms
23,508 KB
testcase_96 AC 107 ms
24,180 KB
testcase_97 AC 101 ms
23,820 KB
testcase_98 AC 96 ms
23,604 KB
testcase_99 AC 117 ms
24,276 KB
testcase_100 AC 118 ms
23,508 KB
testcase_101 AC 125 ms
23,340 KB
testcase_102 AC 106 ms
24,240 KB
testcase_103 AC 113 ms
24,012 KB
testcase_104 AC 114 ms
23,928 KB
testcase_105 AC 109 ms
24,228 KB
testcase_106 AC 102 ms
23,388 KB
testcase_107 AC 115 ms
23,628 KB
testcase_108 AC 102 ms
23,400 KB
testcase_109 AC 125 ms
23,400 KB
testcase_110 AC 105 ms
24,012 KB
testcase_111 AC 105 ms
24,000 KB
testcase_112 AC 95 ms
24,192 KB
testcase_113 AC 135 ms
23,916 KB
testcase_114 AC 135 ms
23,508 KB
testcase_115 AC 113 ms
23,388 KB
testcase_116 WA -
testcase_117 AC 115 ms
23,508 KB
testcase_118 AC 125 ms
24,024 KB
testcase_119 AC 107 ms
23,604 KB
testcase_120 AC 104 ms
23,796 KB
testcase_121 AC 117 ms
23,784 KB
testcase_122 AC 118 ms
23,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int main(){
  int n;
  int p,q;
  scanf("%d",&n);
  if(n==2){
    printf("? 2 1\n");
    fflush(stdout);
    scanf("%d%d",&p,&q);
    if(p==-1 && q==0){printf("! 3 2\n");}
    else{printf("! 2 3\n");}
    fflush(stdout);
    return 0;
  }
  map<pair<int,int>,vector<int>> mp;
  vector<pair<int,int>> ks1,ks2;
  int dmi=0,dma=0;
  vector<int> pmem(n*n-n+1),qmem(n*n-n+1);
  for(int i=2;i<=(n*n-n);i++){
    printf("? 1 %d\n",i);
    fflush(stdout);
    scanf("%d%d",&p,&q);
    pmem[i]=p;
    qmem[i]=q;
    ks1.push_back(make_pair(p,q));
    mp[make_pair(p,q)].push_back(i);
    if(p==q){
      dmi=min(dmi,p);
      dma=max(dma,p);
    }
  }
  int ky=(dma-dmi+1);
  int kh1=n+(n-ky),kh2=(n-ky)*n;
  //printf("<<%d %d>>\n",kh1,kh2);
  int dlt=(n+1)*(dma);
  kh1+=dlt;kh2+=dlt;
  for(int i=n;i<n*n;i++){
    if(i==kh1){continue;}
    p=(kh1/n)-(i/n);
    q=(kh1%n)-(i%n);
    if(p>q){swap(p,q);}
    ks2.push_back(make_pair(p,q));
  }
  sort(ks1.begin(),ks1.end());
  sort(ks2.begin(),ks2.end());
  int onev;
  if(ks1==ks2){onev=kh1;}
  else{onev=kh2;}
  vector<int> res(n*n-n+1,-1);
  res[1]=onev;
  int rp=(onev/n),rq=(onev%n);
  int base=-1,bv=-1;
  for(int i=2;i<=(n*n-n);i++){
    if(mp[make_pair(pmem[i],qmem[i])].size()>1){continue;}
    int cp,cq;
    cp=rp-pmem[i];
    cq=rq-qmem[i];
    if(1<=cp && cp<n && 0<=cq && cq<n){
      res[i]=cp*n+cq;
      base=i;
      bv=res[i];
      continue;
    }
    cp=rp-qmem[i];
    cq=rq-pmem[i];
    res[i]=cp*n+cq;
    base=i;
    bv=res[i];
  }
  int bp=(bv/n),bq=(bv%n);
  for(int i=2;i<=(n*n-n);i++){
    if(mp[make_pair(pmem[i],qmem[i])].size()>1){
      int pr1=mp[make_pair(pmem[i],qmem[i])][0];
      int pr2=mp[make_pair(pmem[i],qmem[i])][1];
      int cp,cq;
      cp=rp-pmem[i];
      cq=rq-qmem[i];
      int pdp,pdq;
      pdp=bp-cp;
      pdq=bq-cq;
      if(pdp>pdq){swap(pdp,pdq);}
      printf("? %d %d\n",base,pr1);
      fflush(stdout);
      int acp,acq;
      scanf("%d%d",&acp,&acq);
      if(pdp==acp && pdq==acq){
        res[pr1]=cp*n+cq;
        cp=rp-qmem[i];
        cq=rq-pmem[i];
        res[pr2]=cp*n+cq;
      }
      else{
        res[pr2]=cp*n+cq;
        cp=rp-qmem[i];
        cq=rq-pmem[i];
        res[pr1]=cp*n+cq;
      }
      mp[make_pair(pmem[i],qmem[i])].clear();
    }
  }
  printf("!");
  for(int i=1;i<=(n*n-n);i++){
    printf(" %d",res[i]);
  }printf("\n");
  fflush(stdout);
  return 0;
}
0