結果

問題 No.355 数当てゲーム(2)
ユーザー tnakao0123tnakao0123
提出日時 2016-04-08 15:52:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,145 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 88,728 KB
実行使用メモリ 24,360 KB
平均クエリ数 70.63
最終ジャッジ日時 2023-09-23 23:46:20
合計ジャッジ時間 4,940 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,400 KB
testcase_01 AC 27 ms
23,388 KB
testcase_02 AC 27 ms
23,964 KB
testcase_03 AC 26 ms
24,036 KB
testcase_04 AC 26 ms
24,024 KB
testcase_05 AC 28 ms
24,048 KB
testcase_06 AC 26 ms
23,376 KB
testcase_07 AC 26 ms
24,048 KB
testcase_08 AC 27 ms
23,364 KB
testcase_09 AC 27 ms
23,508 KB
testcase_10 AC 27 ms
23,964 KB
testcase_11 AC 26 ms
23,856 KB
testcase_12 AC 27 ms
24,252 KB
testcase_13 AC 27 ms
23,388 KB
testcase_14 AC 28 ms
24,348 KB
testcase_15 AC 26 ms
23,508 KB
testcase_16 AC 27 ms
24,312 KB
testcase_17 AC 26 ms
23,532 KB
testcase_18 AC 26 ms
23,520 KB
testcase_19 AC 26 ms
23,652 KB
testcase_20 AC 26 ms
23,844 KB
testcase_21 AC 27 ms
24,264 KB
testcase_22 AC 25 ms
23,376 KB
testcase_23 AC 26 ms
23,568 KB
testcase_24 AC 25 ms
23,616 KB
testcase_25 AC 25 ms
24,048 KB
testcase_26 AC 26 ms
23,376 KB
testcase_27 AC 26 ms
23,988 KB
testcase_28 AC 26 ms
23,616 KB
testcase_29 AC 26 ms
23,520 KB
testcase_30 AC 27 ms
24,036 KB
testcase_31 AC 26 ms
23,376 KB
testcase_32 AC 27 ms
24,276 KB
testcase_33 AC 27 ms
24,324 KB
testcase_34 AC 27 ms
24,336 KB
testcase_35 AC 24 ms
24,336 KB
testcase_36 AC 26 ms
23,832 KB
testcase_37 AC 27 ms
23,412 KB
testcase_38 AC 26 ms
23,592 KB
testcase_39 AC 25 ms
24,288 KB
testcase_40 AC 26 ms
23,628 KB
testcase_41 AC 26 ms
24,048 KB
testcase_42 AC 26 ms
23,520 KB
testcase_43 AC 24 ms
24,360 KB
testcase_44 AC 25 ms
24,024 KB
testcase_45 AC 27 ms
23,364 KB
testcase_46 AC 26 ms
24,024 KB
testcase_47 AC 27 ms
23,508 KB
testcase_48 AC 26 ms
24,216 KB
testcase_49 AC 26 ms
24,024 KB
testcase_50 AC 27 ms
23,628 KB
testcase_51 AC 25 ms
23,616 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;
  vi dps(N), hcs(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 = hcs[i];
      hcs[i] = x;
      ask(hcs, h, b);

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

  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