QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#178518 | #7179. Fischer's Chess Guessing Game | ucup-team368 | AC ✓ | 328ms | 3972kb | C++20 | 4.2kb | 2023-09-14 02:20:43 | 2023-09-14 02:20:44 |
Judging History
answer
#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada
int match(const string &S, const string &T) {
int res = 0;
for (int i = 0; i < 8; ++i) res += (S[i] == T[i]);
return res;
}
int guess(const auto &valid, string ges) {
if (SZ(valid) == 1 and valid[0] == ges) return 0;
vector<int> ans(9, 0);
for (const string &str : valid) ++ans[match(str, ges)];
return *max_element(ALL(ans));
}
string find_best(const auto &global_valid, const auto &valid) {
string ges;
for (int min_worse = SZ(valid) + 1; const string &str : global_valid) {
int res = guess(valid, str);
if (chmin(min_worse, res)) ges = str;
}
return ges;
}
void reduce(auto &valid, string ges, int res) {
vector<string> _valid;
for (string &str : valid) {
if (match(str, ges) == res) _valid.eb(str);
}
valid.swap(_valid);
}
// void solve(const vector<string> &global_valid, vector<string> valid, string ans) {
void solve(const vector<string> &global_valid, vector<string> valid) {
vector<int> candidate;
for (int i = 1; i <= 10; ++i) {
string ges = find_best(global_valid, valid);
// debug(ans, SZ(ges), ges);
cout << ges << "\n" << flush;
// int res = match(ges, ans);
int res; cin >> res;
reduce(valid, ges, res);
candidate.eb(SZ(valid));
if (res == 8) {
// debug(ans, i, candidate);
return;
}
// debug(ans, res);
// debug(ans, i, candidate);
// debug(valid);
}
// debug(ans, candidate);
}
vector<string> init() {
string white = "BBKNNQRR";
vector<string> valid;
do {
int chk_n = 0, pos_r1 = -1, pos_r2 = -1, pos_k = -1;
for (int i = 0; i < 8; ++i) {
if (white[i] == 'B') chk_n ^= i;
if (white[i] == 'K') pos_k = i;
if (white[i] == 'R') {
if (pos_r1 == -1) pos_r1 = i;
else pos_r2 = i;
}
}
if ((chk_n & 1) and pos_r1 < pos_k and pos_k < pos_r2) valid.eb(white);
} while (next_permutation(ALL(white)));
// debug(SZ(valid));
return valid;
}
int32_t main() {
fastIO();
auto valid = init();
// for (string ans : valid) solve(valid, valid, ans);
// solve(valid, valid, "RNQNBKRB"s);
string str;
while (cin >> str and str != "END") {
int game; cin >> game;
// debug(game);
solve(valid, valid);
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
// #define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", "\u001b[33m", __FILE__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), fprintf(stderr, "%s", "\u001b[0m")
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
template <typename T>
ostream & operator << (ostream &os, const vector<T> &vec) {
os << "[";
for (int i = 0; i < SZ(vec); ++i) {
if (i) os << ", ";
os << vec[i];
}
os << "]";
return os;
}
#endif
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 3972kb
input:
GAME 1 1 0 2 4 8 END
output:
NRBBNKQR BRNNKBQR NBRKNQBR QBRKBRNN RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 5 (1 test case)
Test #2:
score: 0
Accepted
time: 325ms
memory: 3692kb
input:
GAME 1 1 0 2 4 8 GAME 2 2 3 3 1 1 8 GAME 3 1 0 1 2 8 GAME 4 1 0 2 2 1 8 GAME 5 2 3 4 2 8 GAME 6 2 2 4 0 0 8 GAME 7 0 2 3 2 0 8 GAME 8 1 3 3 0 8 GAME 9 0 3 3 0 8 GAME 10 0 3 3 1 8 GAME 11 0 5 1 0 8 GAME 12 1 2 2 1 0 8 GAME 13 1 1 5 1 8 GAME 14 0 4 4 3 8 GAME 15 1 2 1 2 1 8 GAME 16 1 0 3 1 0 8 GAME 17...
output:
NRBBNKQR BRNNKBQR NBRKNQBR QBRKBRNN RKRBBQNN NRBBNKQR RNBBQKRN RQKBNNBR BBRNNQKR BBNNRKQR RKRBBNQN NRBBNKQR BRNNKBQR NBRKNQBR BNRKQRNB RKRBBNNQ NRBBNKQR BRNNKBQR NBRKNQBR QBRKBRNN BBNNQRKR RKRBQNBN NRBBNKQR RNBBQKRN RQKBNNBR QNRBBKNR RKRBNQBN NRBBNKQR RNBBQKRN QNRBKNBR BBNNQRKR BBNNRKQR RKRBNNBQ NRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #3:
score: 0
Accepted
time: 319ms
memory: 3784kb
input:
GAME 1 2 2 3 1 2 8 GAME 2 2 2 2 5 2 8 GAME 3 3 1 4 2 8 GAME 4 3 1 3 1 1 8 GAME 5 2 3 5 2 8 GAME 6 3 1 3 0 2 8 GAME 7 1 3 5 1 8 GAME 8 1 3 3 4 8 GAME 9 2 1 3 2 3 8 GAME 10 2 1 0 0 4 8 GAME 11 2 1 1 3 2 8 GAME 12 1 4 3 4 8 GAME 13 0 2 2 3 8 GAME 14 1 1 2 2 2 8 GAME 15 0 1 0 1 8 GAME 16 0 2 2 1 8 GAME ...
output:
NRBBNKQR RNBBQKRN QNRBKNBR BNNQRBKR BBQNNRKR RKQBBNNR NRBBNKQR RNBBQKRN QNRBKNBR RBNNBQKR BBNNQRKR RKNBBQNR NRBBNKQR RBBNQKRN BQNBRNKR BRKRNNQB RKNBBNQR NRBBNKQR RBBNQKRN BQNBRNKR BBRNKNRQ BBNNRKQR RKQBNNBR NRBBNKQR RNBBQKRN RQKBNNBR BBNNRKQR RKNBQNBR NRBBNKQR RBBNQKRN BQNBRNKR BBRNKNRQ BBNQRKNR RKN...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #4:
score: 0
Accepted
time: 323ms
memory: 3824kb
input:
GAME 1 1 2 1 4 0 8 GAME 2 3 1 0 1 8 GAME 3 2 0 3 0 8 GAME 4 1 1 0 1 0 8 GAME 5 2 0 4 0 0 8 GAME 6 3 0 1 0 8 GAME 7 2 1 1 0 8 GAME 8 2 2 1 1 0 8 GAME 9 3 0 0 6 8 GAME 10 2 0 4 1 0 8 GAME 11 2 1 3 1 1 8 GAME 12 3 0 0 4 8 GAME 13 2 2 1 1 2 8 GAME 14 3 1 4 5 8 GAME 15 2 1 1 3 1 8 GAME 16 1 3 0 4 8 GAME ...
output:
NRBBNKQR BRNNKBQR BNRBKRQN BRKQNBNR BBNNQRKR QRKRBBNN NRBBNKQR RBBNQKRN BQNBRNKR BNQRKRNB NRKRBBQN NRBBNKQR RNBBQKRN BRKQNRNB BBQNNRKR NRKRBBNQ NRBBNKQR BRNNKBQR RKQNRBBN BBRKNNRQ BBNNQRKR QRKRBNNB NRBBNKQR RNBBQKRN BRKQNRNB BBNQRNKR BBNNQRKR NRKRBQNB NRBBNKQR RBBNQKRN BNRBQNKR BBNQNRKR NRKRBNQB NRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #5:
score: 0
Accepted
time: 318ms
memory: 3812kb
input:
GAME 1 0 4 5 2 8 GAME 2 0 3 0 2 8 GAME 3 0 4 5 3 8 GAME 4 0 5 1 3 8 GAME 5 0 4 4 2 8 GAME 6 0 6 4 1 8 GAME 7 1 0 2 5 8 GAME 8 3 4 1 3 8 GAME 9 2 2 0 0 2 8 GAME 10 0 1 0 2 8 GAME 11 1 2 3 1 3 8 GAME 12 0 2 4 0 8 GAME 13 1 0 4 2 1 8 GAME 14 0 3 1 1 8 GAME 15 1 1 2 1 3 8 GAME 16 2 2 0 1 1 8 GAME 17 1 0...
output:
NRBBNKQR RKNNRQBB QNRKRBBN BBNNRKRQ RQNKRBBN NRBBNKQR RKNNRQBB BQRNKRNB NRKQRNBB RNQKRBBN NRBBNKQR RKNNRQBB QNRKRBBN BBNNRKRQ RNNKRBBQ NRBBNKQR RKNNRQBB BBNRKQRN BBNQRNKR RQNKRNBB NRBBNKQR RKNNRQBB QNRKRBBN BBRKQNRN RNQKRNBB NRBBNKQR RKNNRQBB BNNRKQRB BBNNQRKR RNNKRQBB NRBBNKQR BRNNKBQR NBRKNQBR QBR...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #6:
score: 0
Accepted
time: 323ms
memory: 3700kb
input:
GAME 1 3 3 1 2 0 8 GAME 2 3 4 0 0 8 GAME 3 4 3 1 0 8 GAME 4 3 2 0 3 8 GAME 5 3 3 0 2 1 8 GAME 6 4 2 0 1 8 GAME 7 1 3 1 1 1 8 GAME 8 2 2 0 4 0 8 GAME 9 2 1 5 1 8 GAME 10 1 2 0 2 1 8 GAME 11 2 1 5 0 8 GAME 12 2 1 6 2 8 GAME 13 3 0 2 3 2 8 GAME 14 2 1 3 5 4 8 GAME 15 4 2 4 4 8 GAME 16 4 1 4 5 8 GAME 17...
output:
NRBBNKQR RBBNQKRN BBQRNKNR BBNRQKRN BBNNRKQR QRBKNBRN NRBBNKQR RBBNQKRN BBNNRQKR BBNQRKNR NRBKQBRN NRBBNKQR BNRBNKRQ BNNRQBKR BNRBQKNR NRBKNBRQ NRBBNKQR RBBNQKRN BBNQRKNR BQRKNRNB QRBKNNRB NRBBNKQR RBBNQKRN BBQRNKNR BBRNKNRQ BBNNQRKR NRBKQNRB NRBBNKQR BNRBNKRQ BBNNRKQR BBNQRKRN NRBKNQRB NRBBNKQR BRN...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #7:
score: 0
Accepted
time: 313ms
memory: 3744kb
input:
GAME 1 1 1 2 2 1 8 GAME 2 2 3 1 1 3 8 GAME 3 1 2 2 3 2 8 GAME 4 0 3 3 3 8 GAME 5 0 3 2 1 8 GAME 6 0 4 1 4 8 GAME 7 2 4 2 0 8 GAME 8 3 3 0 1 1 8 GAME 9 2 4 3 2 8 GAME 10 1 2 2 1 1 8 GAME 11 1 1 1 8 GAME 12 2 3 1 0 2 8 GAME 13 1 2 4 3 8 GAME 14 1 1 4 1 1 8 GAME 15 1 2 4 4 8 GAME 16 0 5 2 3 8 GAME 17 0...
output:
NRBBNKQR BRNNKBQR RKQNRBBN BBRNQKRN BBNNRKQR RBBQKRNN NRBBNKQR RNBBQKRN RQKBNNBR BBNRNKRQ BBNNQRKR RBBNKRQN NRBBNKQR BRNNKBQR BNRBKRQN BBNNRKRQ BBNQNRKR RBBNKRNQ NRBBNKQR RKNNRQBB BQRNKRNB NQNRKRBB RBQNKRBN NRBBNKQR RKNNRQBB BQRNKRNB QRNKBNRB RBNQKRBN NRBBNKQR RKNNRQBB QNRKRBBN BBNNQRKR RBNNKRBQ NRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #8:
score: 0
Accepted
time: 326ms
memory: 3748kb
input:
GAME 1 3 0 3 3 8 GAME 2 4 1 2 2 8 GAME 3 4 1 2 4 8 GAME 4 2 0 1 2 3 8 GAME 5 3 1 1 2 2 8 GAME 6 3 0 1 3 3 8 GAME 7 0 0 6 3 8 GAME 8 1 4 1 5 8 GAME 9 0 1 4 4 8 GAME 10 1 2 6 2 8 GAME 11 2 3 1 1 2 8 GAME 12 1 2 6 1 8 GAME 13 0 2 0 3 8 GAME 14 0 1 5 2 8 GAME 15 1 4 2 3 8 GAME 16 0 2 0 2 8 GAME 17 1 1 2...
output:
NRBBNKQR RBBNQKRN BNRBQNKR BQNBNRKR QRNBKNBR NRBBNKQR BNRBNKRQ NQBRNBKR BBNRKQNR NRQBKNBR NRBBNKQR BNRBNKRQ NQBRNBKR BBNRKQNR NRNBKQBR NRBBNKQR RNBBQKRN BRKQNRNB BBRQKNNR BBNNQRKR QRNNKBBR NRBBNKQR RBBNQKRN BQNBRNKR BBRNNQKR BBNNQRKR NRQNKBBR NRBBNKQR RBBNQKRN BNRBQNKR BBNQNRKR BBNQRKNR NRNQKBBR NRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #9:
score: 0
Accepted
time: 306ms
memory: 3720kb
input:
GAME 1 2 1 0 3 2 8 GAME 2 3 2 3 2 8 GAME 3 4 0 1 3 8 GAME 4 1 3 3 3 3 8 GAME 5 2 0 0 2 2 8 GAME 6 2 0 0 2 3 8 GAME 7 2 2 4 1 1 8 GAME 8 3 1 2 3 1 8 GAME 9 4 1 5 1 8 GAME 10 1 4 4 2 8 GAME 11 2 0 0 4 2 8 GAME 12 2 1 1 1 2 8 GAME 13 3 6 1 2 8 GAME 14 2 6 3 8 GAME 15 3 6 2 3 8 GAME 16 1 1 4 1 2 8 GAME ...
output:
NRBBNKQR RNBBQKRN NRNKBRQB BBRKRNNQ BBNNQRKR QBBRKNNR NRBBNKQR RBBNQKRN BBNQRKNR BBNRQKRN NBBRKQNR NRBBNKQR BNRBNKRQ BRNKQBNR BBNNRKQR NBBRKNQR NRBBNKQR BRNNKBQR RBQNBNKR BBNQRKNR BBNNQRKR QBNRKNBR NRBBNKQR RNBBQKRN BRKQNRNB BQRNKBNR BBNNQRKR NBQRKNBR NRBBNKQR RNBBQKRN BRKQNRNB BQRNKBNR BBNNQRKR NBN...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #10:
score: 0
Accepted
time: 317ms
memory: 3828kb
input:
GAME 1 3 2 6 4 8 GAME 2 2 2 2 3 5 8 GAME 3 4 4 2 4 8 GAME 4 4 5 2 8 GAME 5 3 2 4 4 8 GAME 6 5 5 2 8 GAME 7 2 1 1 4 3 8 GAME 8 3 2 5 2 8 GAME 9 4 2 5 8 GAME 10 3 3 4 3 3 8 GAME 11 4 3 1 3 8 GAME 12 3 4 3 2 8 GAME 13 3 1 2 2 2 8 GAME 14 4 3 1 5 8 GAME 15 5 3 2 1 8 GAME 16 4 5 1 8 GAME 17 5 5 4 8 GAME ...
output:
NRBBNKQR RBBNQKRN BBNQRKNR BBNNRKQR BBRQNKNR NRBBNKQR RNBBQKRN QNRBKNBR RBNNBQKR BBNNQRKR BBRNQKNR NRBBNKQR BNRBNKRQ BBNRKNRQ BBNNQRKR BBRNNKQR NRBBNKQR BNRBNKRQ BBNNRKRQ BQRBNKNR NRBBNKQR RBBNQKRN BBNQRKNR BRNBQKRN BNRBQKNR NRBBNKQR BQRBNNKR NQBBRNKR BNRBNKQR NRBBNKQR RNBBQKRN NRNKBRQB BBNQRKNR BBN...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #11:
score: 0
Accepted
time: 328ms
memory: 3724kb
input:
GAME 1 2 2 3 3 3 8 GAME 2 2 3 4 4 8 GAME 3 2 3 3 3 3 8 GAME 4 1 4 4 3 8 GAME 5 1 3 6 2 8 GAME 6 1 3 4 4 2 8 GAME 7 4 3 3 6 8 GAME 8 3 1 6 5 8 GAME 9 4 3 4 3 8 GAME 10 3 1 3 2 4 8 GAME 11 3 0 3 5 8 GAME 12 2 1 2 5 6 8 GAME 13 5 5 5 8 GAME 14 5 4 0 8 GAME 15 6 1 1 8 GAME 16 4 1 5 3 8 GAME 17 5 3 2 2 8...
output:
NRBBNKQR RNBBQKRN QNRBKNBR BNNQRBKR BBNNQRKR RQNBBNKR NRBBNKQR RNBBQKRN RQKBNNBR QNRBBKNR RNQBBNKR NRBBNKQR RNBBQKRN RQKBNNBR BBRNNQKR BBNNQRKR RNNBBQKR NRBBNKQR BRNNKBQR QNBNRBKR BBNQNRKR RQNNBBKR NRBBNKQR BRNNKBQR RBQNBNKR BBNNRKQR RNQNBBKR NRBBNKQR BRNNKBQR RBQNBNKR BBNQNRKR BBNNRKQR RNNQBBKR NRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Extra Test:
score: 0
Extra Test Passed