結果

問題 No.1306 Exactly 2 Digits
ユーザー butsurizukibutsurizuki
提出日時 2020-11-08 23:42:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,385 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 217,296 KB
実行使用メモリ 24,492 KB
平均クエリ数 1151.30
最終ジャッジ日時 2023-09-24 07:08:24
合計ジャッジ時間 35,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,832 KB
testcase_01 RE -
testcase_02 AC 25 ms
23,592 KB
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 25 ms
24,012 KB
testcase_07 AC 25 ms
23,364 KB
testcase_08 AC 24 ms
24,024 KB
testcase_09 AC 24 ms
24,324 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 25 ms
24,024 KB
testcase_29 RE -
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 27 ms
23,820 KB
testcase_36 WA -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 WA -
testcase_41 WA -
testcase_42 RE -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 RE -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 RE -
testcase_52 WA -
testcase_53 WA -
testcase_54 RE -
testcase_55 WA -
testcase_56 RE -
testcase_57 WA -
testcase_58 WA -
testcase_59 RE -
testcase_60 WA -
testcase_61 RE -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 WA -
testcase_72 RE -
testcase_73 RE -
testcase_74 WA -
testcase_75 RE -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 WA -
testcase_85 WA -
testcase_86 RE -
testcase_87 WA -
testcase_88 WA -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 WA -
testcase_94 WA -
testcase_95 RE -
testcase_96 RE -
testcase_97 WA -
testcase_98 WA -
testcase_99 RE -
testcase_100 WA -
testcase_101 WA -
testcase_102 RE -
testcase_103 RE -
testcase_104 WA -
testcase_105 RE -
testcase_106 RE -
testcase_107 RE -
testcase_108 RE -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 RE -
testcase_117 RE -
testcase_118 RE -
testcase_119 RE -
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:83:12: 警告: ‘acq’ may be used uninitialized [-Wmaybe-uninitialized]
   83 |       scanf("%d%d",&acp,acq);
      |       ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:82:15: 備考: ‘acq’ はここで定義されています
   82 |       int acp,acq;
      |               ^~~

ソースコード

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