QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283778#7179. Fischer's Chess Guessing GameMisukiWA 24ms3620kbC++203.4kb2023-12-15 14:17:252023-12-15 14:17:25

Judging History

你现在查看的是最新测评结果

  • [2023-12-15 14:17:25]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:3620kb
  • [2023-12-15 14:17:25]
  • 提交

answer

#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>

//#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

namespace R = std::ranges;
namespace V = std::views;

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb

template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
  return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(const T &X : arr)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(const T &X : vec)
    os << X << ' ';
  return os;
}

bool valid(string s) {
  array<int, 2> posR = {-1, -1}, posB = {-1, -1};
  int posK = -1;
  for(int i = 0; i < ssize(s); i++) {
    if (s[i] == 'K')
      posK = i;
    if (s[i] == 'R')
      posR[posR[0] != -1] = i;
    if (s[i] == 'B')
      posB[posB[0] != -1] = i;
  }
  return posB[0] % 2 != posB[1] % 2 and posR[0] < posK and posK < posR[1];
}

int match(string s, string t) {
  int res = 0;
  for(int i = 0; i < 8; i++)
    res += s[i] == t[i];
  return res;
}

int mxGroupSize(string qs, vector<string> cand) {
  array<int, 9> cnt = {};
  for(string s : cand)
    cnt[match(qs, s)]++;
  return R::max(cnt);
}

signed main() {
  //ios::sync_with_stdio(false), cin.tie(NULL);

  vector<string> state;
  {
    string s = "BBKNNQRR";
    do {
      if (valid(s))
        state.emplace_back(s);
    } while(next_permutation(s.begin(), s.end()));
  }

  string s; cin >> s;
  while(s != "END") {
    int t; cin >> t;

    vector<string> cand = state;
    bool done = false;
    int guess = 0;
    while(guess < 8 and !done) {
      guess++;
      string qs;
      int mn = INT_MAX;
      for(string s : state)
        if (int tmp = mxGroupSize(s, cand); tmp < mn)
          mn = tmp, qs = s;
      cout << qs << endl;
      int res; cin >> res;
      vector<string> tmp;
      for(string s : cand)
        if (match(qs, s) == res)
          tmp.emplace_back(s);
      cand.swap(tmp);
      if (res == 8)
        done = true;
    }

    if (!done and guess == 8)
      return 0;

    cin >> s;
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 24ms
memory: 3620kb

input:

GAME 1
1
0
2
4
0
0

output:

NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
BBNNQRKR
BBNNQRKR
BBNNQRKR

result:

wrong answer (i) too many guesses in game 1, pos = (test case 1)