結果

問題 No.1959 Prefix MinMax
ユーザー tnakao0123
提出日時 2022-05-28 02:29:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 43,120 KB
実行使用メモリ 25,452 KB
平均クエリ数 26.72
最終ジャッジ日時 2024-09-20 19:57:57
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1959.cc:  No.1959 Prefix MinMax - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N], ps[MAX_N];

/* subroutines */

void query(int n, int as[], int bs[]) {
  putchar('?');
  for (int i = 0; i < n - 1; i++) printf(" %d", as[i]);
  putchar('\n'); fflush(stdout);

  for (int i = 0; i < n; i++) {
    scanf("%d", bs + i);
    if (bs[i] < 1 || bs[i] > n) exit(0);
  }
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d", &n);

    fill(ps, ps + n, 0);

    for (int i = 0; i < n - 1; i++) as[i] = (i & 1);
    query(n, as, bs);

    for (int i = 0, pb = -1; i < n; i++)
      if (pb != bs[i]) pb = ps[i] = bs[i];

    for (int i = 0; i < n - 1; i++) as[i] = (i & 1) ^ 1;
    query(n, as, bs);

    for (int i = 0, pb = -1; i < n; i++)
      if (pb != bs[i]) pb = ps[i] = bs[i];

    putchar('!');
    for (int i = 0; i < n; i++) printf(" %d", ps[i]);
    putchar('\n'); fflush(stdout);
  }

  //sleep(1);
  return 0;
}
0