結果

問題 No.355 数当てゲーム(2)
ユーザー tnakao0123tnakao0123
提出日時 2016-04-08 15:41:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,712 KB
実行使用メモリ 24,468 KB
平均クエリ数 72.48
最終ジャッジ日時 2023-09-23 10:20:58
合計ジャッジ時間 6,034 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
24,264 KB
testcase_01 AC 27 ms
23,412 KB
testcase_02 WA -
testcase_03 AC 29 ms
23,784 KB
testcase_04 AC 28 ms
24,468 KB
testcase_05 AC 31 ms
23,484 KB
testcase_06 AC 27 ms
24,264 KB
testcase_07 AC 28 ms
23,952 KB
testcase_08 WA -
testcase_09 AC 28 ms
23,544 KB
testcase_10 WA -
testcase_11 AC 28 ms
23,496 KB
testcase_12 AC 28 ms
23,784 KB
testcase_13 AC 28 ms
23,364 KB
testcase_14 AC 28 ms
24,324 KB
testcase_15 WA -
testcase_16 AC 28 ms
24,384 KB
testcase_17 AC 28 ms
24,228 KB
testcase_18 AC 28 ms
23,328 KB
testcase_19 AC 29 ms
23,616 KB
testcase_20 AC 29 ms
23,952 KB
testcase_21 AC 29 ms
23,184 KB
testcase_22 AC 28 ms
23,592 KB
testcase_23 AC 28 ms
23,580 KB
testcase_24 AC 28 ms
23,532 KB
testcase_25 AC 28 ms
24,288 KB
testcase_26 WA -
testcase_27 AC 28 ms
23,832 KB
testcase_28 AC 27 ms
24,204 KB
testcase_29 AC 29 ms
23,388 KB
testcase_30 AC 28 ms
24,336 KB
testcase_31 AC 27 ms
23,412 KB
testcase_32 AC 28 ms
23,412 KB
testcase_33 AC 28 ms
23,388 KB
testcase_34 AC 28 ms
24,348 KB
testcase_35 AC 25 ms
23,952 KB
testcase_36 AC 28 ms
23,376 KB
testcase_37 AC 28 ms
23,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 27 ms
23,568 KB
testcase_43 WA -
testcase_44 AC 27 ms
24,288 KB
testcase_45 AC 27 ms
24,000 KB
testcase_46 AC 27 ms
23,376 KB
testcase_47 AC 26 ms
24,036 KB
testcase_48 AC 27 ms
23,424 KB
testcase_49 AC 27 ms
24,228 KB
testcase_50 AC 27 ms
23,328 KB
testcase_51 AC 27 ms
23,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 355.cc: No.355 数当てゲーム(2) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 4;
const int PN = 24; // =4!

/* typedef */

typedef vector<int> vi;

/* global variables */

int cs[10];
vi pns[PN];

/* subroutines */

void ask(vi &ds, int &h, int &b) {
  for (int i = 0; i < N; i++) {
    if (i) putchar(' ');
    printf("%d", ds[i]);
  }
  putchar('\n');
  cout.flush();

  cin >> h >> b;
  if (h == N) exit (0);
}

int check(vi &ds) {
  int h, b, n, hcs[N];
  vi dps(N);
  bool first = true;

  for (int i = 0; i < PN; i++) {
    vi &pni = pns[i];
    for (int j = 0; j < N; j++) dps[j] = ds[pni[j]];
    ask(dps, h, b);
    n = h + b;

    if (h == n) {
      if (first) {
	for (int j = 0; j < N; j++) hcs[j] = dps[j];
	first = false;
      }
      else
	for (int j = 0; j < N; j++)
	  if (hcs[j] != dps[j]) hcs[j] = -1;
    }
  }

  if (n == 3) {
    int x = 0;
    for (int i = 0; i < N && x == ds[i]; i++, x++);
    for (int i = 0; i < N; i++) {
      int tmp = ds[i];
      ds[i] = x;
      ask(ds, h, b);
      ds[i] = tmp;

      if (h == 3) {
	hcs[i] = -1;
	break;
      }
    }
  }

  for (int j = 0; j < N; j++)
    if (hcs[j] >= 0) cs[hcs[j]] = j;
  //for (int j = 0; j < N; j++) printf("%d ", hcs[j]); putchar('\n');
  return n;
}

/* main */

int main() {
  vi pn(N);
  for (int i = 0; i < N; i++) pn[i] = i;
  for (int i = 0; i < PN; i++) {
    pns[i] = pn;
    next_permutation(pn.begin(), pn.end());
  } 

  memset(cs, -1, sizeof(cs));

  vi ds(N);
  for (int i = 0; i < N; i++) ds[i] = i;
  int n0 = check(ds);
  for (int i = 0; i < N; i++) ds[i] = i + 4;
  int n1 = check(ds);
  for (int i = 0; i < N; i++) ds[i] = i + 6;
  int n2 = check(ds);

  for (int i = 0; i < 10; i++)
    if (cs[i] >= 0) ds[cs[i]] = i;
  int h, b;
  ask(ds, h, b);
  return 0;
}
0