QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283785#7179. Fischer's Chess Guessing GameMisukiWA 1060ms3952kbC++203.4kb2023-12-15 14:33:342023-12-15 14:33:34

Judging History

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

  • [2023-12-15 14:33:34]
  • 评测
  • 测评结果:WA
  • 用时:1060ms
  • 内存:3952kb
  • [2023-12-15 14:33:34]
  • 提交

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 : 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 19ms
memory: 3952kb

input:

GAME 1
1
2
2
1
2
8
END

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN

result:

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

Test #2:

score: -100
Wrong Answer
time: 1060ms
memory: 3752kb

input:

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

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NBNRBKRQ
BQNBRNKR
RKRBBNQN
NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
RBKNBQNR
RKRBBNNQ
NRBBNKQR
BNRKQBNR
RNBQKRNB
BBNQRNKR
QBRKNRBN
RKRBQNBN
NRBBNKQR
RBBNKQNR
NBNQBRKR
BRKBRQNN
QRBKRNNB
RKRBNQBN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NRK...

result:

wrong answer (i) too many guesses in game 62, pos =