結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,400 KB
testcase_01 AC 27 ms
24,000 KB
testcase_02 AC 27 ms
24,348 KB
testcase_03 AC 27 ms
23,340 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 27 ms
23,400 KB
testcase_07 AC 27 ms
23,640 KB
testcase_08 AC 27 ms
23,352 KB
testcase_09 AC 27 ms
23,832 KB
testcase_10 AC 28 ms
23,448 KB
testcase_11 AC 26 ms
23,868 KB
testcase_12 WA -
testcase_13 AC 27 ms
24,000 KB
testcase_14 AC 28 ms
24,012 KB
testcase_15 AC 26 ms
23,412 KB
testcase_16 WA -
testcase_17 AC 28 ms
24,024 KB
testcase_18 WA -
testcase_19 AC 26 ms
24,360 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 27 ms
24,336 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 27 ms
23,496 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 27 ms
23,868 KB
testcase_29 AC 29 ms
24,012 KB
testcase_30 WA -
testcase_31 AC 27 ms
23,640 KB
testcase_32 AC 27 ms
24,336 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 28 ms
23,616 KB
testcase_36 WA -
testcase_37 AC 27 ms
23,640 KB
testcase_38 AC 27 ms
23,400 KB
testcase_39 AC 29 ms
24,228 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 27 ms
23,520 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 30 ms
23,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 34 ms
23,688 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 38 ms
24,468 KB
testcase_55 WA -
testcase_56 AC 42 ms
24,312 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 45 ms
23,412 KB
testcase_60 WA -
testcase_61 AC 55 ms
23,364 KB
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 63 ms
23,352 KB
testcase_69 AC 68 ms
23,460 KB
testcase_70 AC 68 ms
23,640 KB
testcase_71 WA -
testcase_72 AC 73 ms
24,240 KB
testcase_73 AC 74 ms
23,952 KB
testcase_74 WA -
testcase_75 AC 76 ms
23,352 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 AC 111 ms
24,216 KB
testcase_81 AC 97 ms
23,568 KB
testcase_82 AC 112 ms
23,688 KB
testcase_83 AC 118 ms
23,448 KB
testcase_84 WA -
testcase_85 WA -
testcase_86 AC 111 ms
23,352 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 AC 122 ms
24,012 KB
testcase_90 AC 104 ms
24,036 KB
testcase_91 AC 123 ms
24,372 KB
testcase_92 AC 108 ms
23,616 KB
testcase_93 WA -
testcase_94 WA -
testcase_95 AC 119 ms
23,520 KB
testcase_96 AC 102 ms
23,856 KB
testcase_97 WA -
testcase_98 WA -
testcase_99 AC 117 ms
24,036 KB
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 106 ms
23,376 KB
testcase_103 AC 116 ms
24,312 KB
testcase_104 WA -
testcase_105 AC 115 ms
23,556 KB
testcase_106 AC 105 ms
23,388 KB
testcase_107 AC 112 ms
24,228 KB
testcase_108 AC 106 ms
23,616 KB
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 AC 137 ms
24,072 KB
testcase_117 AC 121 ms
24,012 KB
testcase_118 AC 128 ms
23,868 KB
testcase_119 AC 110 ms
24,048 KB
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます

ソースコード

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;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