結果

問題 No.2496 LCM between Permutations
ユーザー planesplanes
提出日時 2023-11-13 02:27:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,906 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 175,968 KB
実行使用メモリ 24,012 KB
平均クエリ数 952.93
最終ジャッジ日時 2023-11-13 02:28:02
合計ジャッジ時間 6,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,012 KB
testcase_01 AC 25 ms
24,012 KB
testcase_02 AC 25 ms
24,012 KB
testcase_03 AC 24 ms
24,012 KB
testcase_04 AC 25 ms
24,012 KB
testcase_05 AC 25 ms
24,012 KB
testcase_06 AC 25 ms
24,012 KB
testcase_07 AC 25 ms
24,012 KB
testcase_08 AC 26 ms
24,012 KB
testcase_09 AC 25 ms
24,012 KB
testcase_10 AC 28 ms
24,012 KB
testcase_11 AC 26 ms
24,012 KB
testcase_12 AC 24 ms
24,012 KB
testcase_13 AC 26 ms
24,012 KB
testcase_14 AC 26 ms
24,012 KB
testcase_15 AC 31 ms
24,012 KB
testcase_16 AC 38 ms
24,012 KB
testcase_17 AC 34 ms
24,012 KB
testcase_18 AC 94 ms
24,012 KB
testcase_19 AC 71 ms
24,012 KB
testcase_20 AC 95 ms
24,012 KB
testcase_21 AC 86 ms
24,012 KB
testcase_22 AC 81 ms
24,012 KB
testcase_23 AC 110 ms
24,012 KB
testcase_24 AC 92 ms
24,012 KB
testcase_25 AC 113 ms
24,012 KB
testcase_26 AC 115 ms
24,000 KB
testcase_27 AC 115 ms
24,000 KB
testcase_28 AC 115 ms
24,000 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:125:19: warning: 'one' may be used uninitialized [-Wmaybe-uninitialized]
  125 |   cout<<"? "<<one+1<<" "<<i+1<<endl;
      |                   ^
main.cpp:118:4: note: 'one' was declared here
  118 | ll one;
      |    ^~~
main.cpp:80:31: warning: 'to' may be used uninitialized [-Wmaybe-uninitialized]
   80 |   cout<<"? "<<v[0]+1<<" "<<to+1<<endl;
      |                               ^
main.cpp:75:6: note: 'to' was declared here
   75 |   ll to;
      |      ^~

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll N;cin>>N;
  if(N==1) {
    cout<<"! "<<1<<" "<<1<<endl;
    return 0;
  }

  vector<bool> note(N+1);
  
  for(ll i=2;i<=N;i++) {
    if(note[i]) continue;
    for(ll j=2;j*i<=N;j++) note[j*i]=true;
  }


vector<ll> A(N),B(N);

vector<ll> C(N);
for(ll i=0;i<N;i++) {
  cout<<"? "<<1<<" "<<i+1<<endl;
  ll X;cin>>X;
  C[i]=X;
}

//ok

ll mi=INF;
for(ll i=0;i<N;i++) mi=min(mi,C[i]);
A[0]=mi;
ll ma=0,ind=0;

for(ll i=0;i<N;i++) {
  ll k=C[i]/A[0];
  if(!note[k]&&ma<k) {
    ma=k;
    ind=i;
  }
}

B[ind]=ma;//1もありうる

vector<ll> D(N);
for(ll i=1;i<N;i++) {
  cout<<"? "<<i+1<<" "<<ind+1<<endl;
  ll X;cin>>X;
  D[i]=X;
}

for(ll i=1;i<N;i++) {
  A[i]=D[i]/ma;
  if(ma*2<=N&&ma*2==D[i]) A[i]=D[i];

}

vector<ll> v(0);
for(ll i=0;i<N;i++) {
  if(A[i]==ma*2) v.push_back(i);
}

//maが1出ないかつma*2<=Nのとき
if(v.size()==2) {
  ll to;
  for(ll i=0;i<N;i++) {
    if(C[i]==A[0]) to=i;
  }

  cout<<"? "<<v[0]+1<<" "<<to+1<<endl;
  ll X;cin>>X;
  if(X%ma==0) {
    A[v[0]]=ma*2;
    A[v[1]]=2;
  }
  else {
    A[v[0]]=2;
    A[v[1]]=ma*2;
  }
}


//maが1出ない場合
vector<ll> vec(0);
for(ll i=0;i<N;i++) {
if(A[i]==1) vec.push_back(i);
}

if(vec.size()==2) {
ll to=0;
for(ll i=0;i<N;i++) {
  if(C[i]==A[0]) to=i;
}

cout<<"? "<<vec[0]+1<<" "<<to+1<<endl;
ll X;cin>>X;
if(X%ma==0) {
  A[vec[0]]=ma;
  A[vec[1]]=1;
}
else {
  A[vec[0]]=1;
  A[vec[1]]=ma;
}
}


ll one;
for(ll i=0;i<N;i++) {
  if(A[i]==1) one=i;
}

for(ll i=0;i<N;i++) {
  if(i==ind) continue;
  cout<<"? "<<one+1<<" "<<i+1<<endl;
  ll X;cin>>X;
  B[i]=X;
}


cout<<"! ";
for(auto x:A) cout<<x<<" ";
for(auto x:B) cout<<x<<" ";
cout<<endl;
}






0