QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283788#7179. Fischer's Chess Guessing GameMisukiTL 26ms3556kbC++203.6kb2023-12-15 14:37:322023-12-15 14:37:33

Judging History

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

  • [2023-12-15 14:37:33]
  • 评测
  • 测评结果:TL
  • 用时:26ms
  • 内存:3556kb
  • [2023-12-15 14:37:32]
  • 提交

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;
    vector<string> nonCand;
    bool done = false;
    int guess = 0;
    while(guess < 8 and !done) {
      guess++;
      string qs;
      int mn = INT_MAX;
      for(string s : nonCand)
        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, tmp2;
      for(string s : cand) {
        if (match(qs, s) == res)
          tmp.emplace_back(s);
        else
          tmp2.emplace_back(s);
      }
      cand.swap(tmp);
      nonCand.swap(tmp2);
      if (res == 8)
        done = true;
    }

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

    cin >> s;
  }


  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 26ms
memory: 3556kb

input:

GAME 1
3
0
2
3
8
END

output:

RQKNBBRN
NRKQNBBR
RNBNKQRB
RQNKBRNB
RKRBBQNN

result:

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

Test #2:

score: -100
Time Limit Exceeded

input:

GAME 1
3
0
2
3
8
GAME 2
3
0
1
8
GAME 3
2
2
4
3
8
GAME 4
2
0
2
3
8
GAME 5
2
0
1
2
4
8
GAME 6
1
0
3
5
8
GAME 7
4
3
3
8
GAME 8
5
4
3
8
GAME 9
4
4
4
4
8
GAME 10
2
3
1
0
8
GAME 11
3
0
4
2
8
GAME 12
3
0
3
6
8
GAME 13
3
4
3
8
GAME 14
4
3
4
4
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...

output:

RQKNBBRN
NRKQNBBR
RNBNKQRB
RQNKBRNB
RKRBBQNN
RQKNBBRN
NRKQNBBR
RNBNKQRB
RKRBBNQN
RQKNBBRN
NRKQBBNR
RBNKBRNQ
RNBKRBNQ
RKRBBNNQ
RQKNBBRN
NRKQBBNR
BNRNQKRB
RKNNRQBB
RKRBQNBN
RQKNBBRN
NRKQBBNR
BNRNQKRB
RQNKRNBB
RNQBKRBN
RKRBNQBN
RQKNBBRN
NRQNBBKR
RKBQRNNB
RKBBNRNQ
RKRBNNBQ
RQKNBBRN
RQBNKBNR
RQNKRBBN
RKR...

result: