結果

問題 No.355 数当てゲーム(2)
ユーザー motimoti
提出日時 2016-04-01 23:49:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,764 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 108,716 KB
実行使用メモリ 24,468 KB
平均クエリ数 41.87
最終ジャッジ日時 2023-09-23 23:32:15
合計ジャッジ時間 4,240 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,664 KB
testcase_01 AC 21 ms
24,216 KB
testcase_02 AC 21 ms
24,336 KB
testcase_03 AC 21 ms
24,360 KB
testcase_04 AC 20 ms
24,408 KB
testcase_05 AC 20 ms
24,060 KB
testcase_06 AC 23 ms
23,412 KB
testcase_07 AC 22 ms
23,664 KB
testcase_08 AC 21 ms
23,640 KB
testcase_09 AC 21 ms
23,388 KB
testcase_10 AC 20 ms
23,664 KB
testcase_11 AC 21 ms
24,384 KB
testcase_12 AC 21 ms
24,036 KB
testcase_13 AC 21 ms
23,664 KB
testcase_14 AC 20 ms
24,324 KB
testcase_15 AC 21 ms
23,640 KB
testcase_16 AC 22 ms
24,024 KB
testcase_17 AC 21 ms
23,400 KB
testcase_18 AC 21 ms
23,436 KB
testcase_19 AC 22 ms
23,676 KB
testcase_20 AC 21 ms
23,844 KB
testcase_21 AC 22 ms
24,348 KB
testcase_22 AC 23 ms
23,676 KB
testcase_23 AC 21 ms
23,820 KB
testcase_24 AC 20 ms
23,652 KB
testcase_25 AC 22 ms
23,388 KB
testcase_26 AC 22 ms
23,640 KB
testcase_27 AC 20 ms
23,640 KB
testcase_28 AC 22 ms
24,408 KB
testcase_29 AC 22 ms
23,544 KB
testcase_30 AC 21 ms
24,024 KB
testcase_31 AC 21 ms
23,664 KB
testcase_32 AC 21 ms
23,412 KB
testcase_33 AC 23 ms
23,376 KB
testcase_34 AC 21 ms
23,976 KB
testcase_35 AC 20 ms
23,856 KB
testcase_36 AC 20 ms
24,372 KB
testcase_37 AC 21 ms
24,216 KB
testcase_38 AC 21 ms
24,276 KB
testcase_39 AC 21 ms
23,532 KB
testcase_40 AC 21 ms
23,400 KB
testcase_41 AC 22 ms
24,024 KB
testcase_42 AC 23 ms
23,556 KB
testcase_43 AC 24 ms
23,652 KB
testcase_44 AC 20 ms
24,468 KB
testcase_45 AC 24 ms
23,964 KB
testcase_46 AC 21 ms
24,372 KB
testcase_47 AC 20 ms
24,264 KB
testcase_48 AC 22 ms
23,388 KB
testcase_49 AC 20 ms
23,628 KB
testcase_50 AC 21 ms
23,820 KB
testcase_51 AC 22 ms
23,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  std::random_device rd;
  std::mt19937 g(rd());
  vector<int> ten(10); iota(all(ten), 0);
  vector<int> nones;

#if 1
  #define ASK(A, B, C, D) cout << A << " " << B << " " << C << " " << D << endl; cout << flush;
  #define QUERY() int hit, blow; cin >> hit >> blow;
#else

  vector<int> ans; std::shuffle(ten.begin(), ten.end(), g); rep(i, 4) ans.push_back(ten[i]);
  rep(i, 4) cout << ans[i] << " ";
  cout << endl << endl;
  vector<int> q(4);
  #define ASK(A, B, C, D) q[0] = A, q[1] = B, q[2] = C, q[3] = D; printf("%d %d %d %d\n", A, B, C, D);
  #define QUERY() int hit = 0; rep(i, 4) hit += q[i] == ans[i]; int blow = 0; rep(i, 4) rep(j, 4) if(i != j && q[i] == ans[j]) blow ++; printf("%d %d\n", hit, blow);

#endif

  auto invalid = [&](int x, int skipid) {
    rep(i, 4) {
      if(skipid != i && x == nones[i]) {
        return true;
      }
    }
    return false;
  };

  while(1) {
    std::shuffle(ten.begin(), ten.end(), g);
    ASK(ten[0], ten[1], ten[2], ten[3])
    QUERY()
    if(hit == 4) {
      exit(0);
    }
    if(hit == 0 && blow == 0) {
      rep(i, 4) nones.push_back(ten[i]);
      break;
    }
  }

  int a = -1;
  rep(i, 10) {
    if(invalid(i, 0)) { continue; }
    ASK(i, nones[1], nones[2], nones[3])
    QUERY()
    assert(hit != 4);
    if(hit > 0) {
      a = i;
    }
  }
  int b = -1;
  rep(i, 10) {
    if(invalid(i, 1)) { continue; }
    ASK(nones[0], i, nones[2], nones[3])
    QUERY()
    assert(hit != 4);
    if(hit > 0) {
      b = i;
    }
  }
  int c = -1;
  rep(i, 10) {
    if(invalid(i, 2)) { continue; }
    ASK(nones[0], nones[1], i, nones[3])
    QUERY()
    assert(hit != 4);
    if(hit > 0) {
      c = i;
    }
  }
  int d = -1;
  rep(i, 10) {
    if(invalid(i, 3)) { continue; }
    ASK(nones[0], nones[1], nones[2], i)
    QUERY()
    assert(hit != 4);
    if(hit > 0) {
      d = i;
    }
  }

  ASK(a, b, c, d)
  QUERY()
  assert(hit == 4);

  return 0;   
}
0