QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283787#7179. Fischer's Chess Guessing GameMisukiTL 42ms3588kbC++203.5kb2023-12-15 14:34:492023-12-15 14:34:50

Judging History

This is the latest submission verdict.

  • [2023-12-15 14:34:50]
  • Judged
  • Verdict: TL
  • Time: 42ms
  • Memory: 3588kb
  • [2023-12-15 14:34:49]
  • Submitted

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;
      for(string s : cand)
        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: 100
Accepted
time: 42ms
memory: 3588kb

input:

GAME 1
3
0
3
8
END

output:

RQKNBBRN
NRKQNBBR
BNRBQKRN
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 4 (1 test case)

Test #2:

score: -100
Time Limit Exceeded

input:

GAME 1
3
0
3
8
GAME 2
3
0
3
6
8
GAME 3
2
2
4
3
8
GAME 4
2
0
2
3
8
GAME 5
2
0
1
4
8
GAME 6
1
0
3
1
8
GAME 7
4
3
2
5
8
GAME 8
5
4
0
8
GAME 9
4
4
4
4
8
GAME 10
2
3
2
0
8
GAME 11
3
0
1
3
8
GAME 12
3
0
1
2
8
GAME 13
3
4
3
8
GAME 14
4
3
2
8
GAME 15
3
3
2
3
8
GAME 16
1
0
5
3
8
GAME 17
2
0
4
1
4
8
GAME 18
2...

output:

RQKNBBRN
NRKQNBBR
BNRBQKRN
RKRBBQNN
RQKNBBRN
NRKQNBBR
BNRBQKRN
RKRBBQNN
RKRBBNQN
RQKNBBRN
NRKQBBNR
RBNKBRNQ
RNBKRBNQ
RKRBBNNQ
RQKNBBRN
NRKQBBNR
BNRNQKRB
RKNNRQBB
RKRBQNBN
RQKNBBRN
NRKQBBNR
BNRNQKRB
RNKBQRBN
RKRBNQBN
RQKNBBRN
NRQNBBKR
RKBQRNNB
BNRQKRNB
RKRBNNBQ
RQKNBBRN
RQBNKBNR
BRQKNBRN
RKRNQBBN
RKR...

result: