結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,820 KB
testcase_01 AC 25 ms
23,400 KB
testcase_02 AC 26 ms
23,412 KB
testcase_03 AC 25 ms
24,000 KB
testcase_04 AC 26 ms
24,324 KB
testcase_05 AC 26 ms
23,376 KB
testcase_06 AC 25 ms
23,616 KB
testcase_07 AC 26 ms
23,364 KB
testcase_08 AC 25 ms
24,036 KB
testcase_09 AC 26 ms
23,400 KB
testcase_10 AC 26 ms
23,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 26 ms
24,036 KB
testcase_14 WA -
testcase_15 AC 25 ms
23,364 KB
testcase_16 AC 24 ms
23,496 KB
testcase_17 AC 24 ms
23,484 KB
testcase_18 WA -
testcase_19 AC 25 ms
23,604 KB
testcase_20 WA -
testcase_21 AC 25 ms
24,240 KB
testcase_22 AC 25 ms
23,616 KB
testcase_23 AC 25 ms
24,252 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 26 ms
24,024 KB
testcase_29 AC 25 ms
24,252 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 26 ms
23,364 KB
testcase_34 WA -
testcase_35 AC 26 ms
23,988 KB
testcase_36 AC 25 ms
23,820 KB
testcase_37 AC 26 ms
23,640 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 25 ms
24,312 KB
testcase_43 AC 26 ms
24,228 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 31 ms
23,520 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 36 ms
24,024 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 70 ms
23,364 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 AC 105 ms
24,036 KB
testcase_98 AC 97 ms
24,336 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 AC 97 ms
23,352 KB
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 AC 106 ms
23,340 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;
    base=i;
    bv=res[i];
    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;
  }
  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