結果

問題 No.1959 Prefix MinMax
ユーザー 👑 tute7627tute7627
提出日時 2022-05-14 18:06:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,873 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 209,324 KB
実行使用メモリ 24,456 KB
平均クエリ数 89.84
最終ジャッジ日時 2023-09-30 10:04:18
合計ジャッジ時間 8,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,340 KB
testcase_01 AC 28 ms
23,604 KB
testcase_02 AC 26 ms
23,340 KB
testcase_03 AC 26 ms
23,340 KB
testcase_04 AC 26 ms
23,664 KB
testcase_05 AC 26 ms
23,664 KB
testcase_06 AC 27 ms
23,796 KB
testcase_07 AC 84 ms
24,048 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 84 ms
23,388 KB
testcase_13 WA -
testcase_14 AC 82 ms
24,228 KB
testcase_15 WA -
testcase_16 AC 86 ms
23,508 KB
testcase_17 AC 86 ms
23,988 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 82 ms
23,868 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 84 ms
23,988 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 86 ms
24,324 KB
testcase_28 AC 84 ms
23,496 KB
testcase_29 AC 83 ms
23,556 KB
testcase_30 AC 92 ms
24,348 KB
testcase_31 AC 85 ms
23,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

vector<int>ask(vector<int>A){
  cout << "?";
  for(int i = 0; i < A.size(); i++){
    cout << " " << A[i];
  }
  cout << endl;
  vector<int>B(A.size() + 1);
  for(int i = 0; i < A.size() + 1; i++){
    cin >> B[i];
  }
  return B;
}

struct RandomNumberGenerator {
  mt19937_64 mt;

  RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) { // [a, b)
    uniform_int_distribution< int > dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) { // [0, b)
    return (*this)(0, b);
  }
};
RandomNumberGenerator rng;

int main(){
  int T;
  cin >> T;
  while(T--){
    int N;
    cin >> N;
    vector<int>P(N, -1);
    vector<int>l(N, 1), r(N, N), used(N + 1, 0);
    int num = 10;
    while(*min_element(P.begin(), P.end()) == -1){
      num--;
      if(num<0)break;
      vector<int>A(N - 1);
      for(int i = 0; i < N - 1; i++){
        A[i] = rng(0, 2);
      }
      auto B = ask(A);
      P[0] = B[0];
      for(int i = 1; i < N; i++){
        if(B[i] != B[i - 1]){
          P[i] = B[i];
        }
        else{
          if(A[i - 1] == 0){
            l[i] = B[i];
          }
          else{
            r[i] = B[i];
          }
        }
      }
    }
    vector<int>ord;
    for(int i = 0; i < N; i++){
      if(P[i] != -1){
        used[P[i]] = true;
      }
      else{
        ord.push_back(i);
      }
    }
    sort(ord.begin(),ord.end(),[&](int i,int j){
      return r[i] - l[i] < r[j] - l[j];
    });
    for(auto i:ord){
      if(P[i] == -1){
        for(int j = l[i]; j <= r[i]; j++){
          if(!used[j]){
            used[j] = true;
            P[i] = j;
            break;
          }
        }
      }
    }
    cout << "!";
    for(int i = 0; i < N; i++){
      cout << " " << P[i];
    }
    cout << endl;
  }
  return 0;
}
0