QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292102 | #7179. Fischer's Chess Guessing Game | OAleksa | AC ✓ | 1586ms | 3740kb | C++14 | 2.0kb | 2023-12-27 18:27:26 | 2023-12-27 18:27:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 960;
vector<char> sv = {'K', 'Q', 'R', 'R', 'B', 'B', 'N', 'N'};
vector<string> perm;
int good(vector<char> ord) {
int x = -1, y = -1, z = -1, b = -1, a = -1;
for (int i = 0;i < 8;i++) {
if (ord[i] == 'K')
z = i;
else if (ord[i] == 'B') {
if (x == -1)
x = i;
else
y = i;
}
else if (ord[i] == 'R') {
if (a == -1)
a = i;
else
b = i;
}
}
return z < b && z > a && x % 2 != y % 2;
};
int diff(string a, string b) {
int r = 0;
for (int x = 0;x < 8;x++)
r += (a[x] == b[x]);
return r;
};
int Ask(string s) {
cout << s << endl;
int r;
cin >> r;
return r;
}
void go() {
vector<string> tr = perm, temp;
while (tr.size() > 1) {
int mn = 1e9;
string bst;
for (auto u : perm) {
vector<int> cnt(10);
for (auto x : tr)
++cnt[diff(u, x)];
int mx = *max_element(cnt.begin(), cnt.end());
if (mx < mn) {
mn = mx;
bst = u;
}
}
temp.clear();
int r = Ask(bst);
if (r == 8)
return;
for (auto u : tr) {
if (diff(u, bst) == r)
temp.push_back(u);
}
tr = temp;
}
Ask(tr[0]);
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
//freopen("newbarn.in", "r", stdin);
//freopen(newbarn.out", "w", stdout);
int tt = 1;
//cin >> tt;
while (tt--) {
vector<int> order(8);
iota(order.begin(), order.end(), 0);
map<string, int> bio;
do {
vector<char> t;
for (int i = 0;i < 8;i++)
t.push_back(sv[order[i]]);
if (good(t)) {
string s;
for (auto x : t)
s += x;
if (bio[s])
continue;
bio[s] = 1;
perm.push_back(s);
}
} while (next_permutation(order.begin(), order.end()));
assert(perm.size() == N);
while (true) {
string s;
cin >> s;
if (s == "GAME") {
cin >> s;
go();
}
else
break;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 20ms
memory: 3660kb
input:
GAME 1 4 3 3 2 8 END
output:
RQKBBNRN RQKNBRNB RKQNBNRB QRKRBNNB RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 5 (1 test case)
Test #2:
score: 0
Accepted
time: 1555ms
memory: 3740kb
input:
GAME 1 4 3 3 2 8 GAME 2 5 5 5 8 GAME 3 4 3 4 2 8 GAME 4 4 1 3 1 8 GAME 5 3 1 3 1 3 8 GAME 6 3 1 2 4 0 8 GAME 7 3 2 0 4 2 8 GAME 8 3 1 6 3 8 GAME 9 2 2 1 3 3 8 GAME 10 3 2 1 3 2 8 GAME 11 2 3 3 3 0 8 GAME 12 3 1 4 3 8 GAME 13 2 0 5 4 8 GAME 14 2 0 3 2 2 8 GAME 15 1 3 3 3 1 8 GAME 16 2 0 6 2 8 GAME 17...
output:
RQKBBNRN RQKNBRNB RKQNBNRB QRKRBNNB RKRBBQNN RQKBBNRN RKNRBNQB RKNBBQRN RKRBBNQN RQKBBNRN RQKNBRNB RKQNBNRB QRKRBBNN RKRBBNNQ RQKBBNRN RQKNBRNB RKBQRNNB QRBNKNRB RKRBQNBN RQKBBNRN NRQBBKNR RKNRBBQN QRKNBBRN QRKRNBBN RKRBNQBN RQKBBNRN NRQBBKNR RKNRBBQN QRKBNNBR QRKRBBNN RKRBNNBQ RQKBBNRN NRQBBKNR QRB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #3:
score: 0
Accepted
time: 1436ms
memory: 3620kb
input:
GAME 1 4 3 5 3 8 GAME 2 3 4 3 2 8 GAME 3 4 2 4 3 8 GAME 4 3 3 5 0 8 GAME 5 3 2 3 0 0 8 GAME 6 2 3 4 2 0 8 GAME 7 2 3 4 6 8 GAME 8 2 3 5 0 8 GAME 9 2 2 3 1 1 8 GAME 10 1 2 4 8 GAME 11 1 2 4 6 8 GAME 12 1 1 0 3 2 8 GAME 13 4 4 4 5 8 GAME 14 5 5 3 8 GAME 15 4 4 6 4 8 GAME 16 4 2 3 4 8 GAME 17 3 0 1 2 3...
output:
RQKBBNRN RQKNBRNB RKQNBNRB QRKRBNNB RKQBBNNR RQKBBNRN NRQBBKNR QBNRBNKR QRKRBBNN RKNBBQNR RQKBBNRN RQKNBRNB RNBBQNKR QBRKBNNR RKNBBNQR RQKBBNRN NRQBBKNR QRKBNNBR QRKRBBNN RKQBNNBR RQKBBNRN NRQBBKNR QRBBNNKR QRBKNBRN QRKRBBNN RKNBQNBR RQKBBNRN NRKBBQNR RQNBBKNR RKQRBBNN QRKRBBNN RKNBNQBR RQKBBNRN NRK...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #4:
score: 0
Accepted
time: 1586ms
memory: 3696kb
input:
GAME 1 3 3 3 5 8 GAME 2 3 3 2 6 8 GAME 3 2 5 4 2 8 GAME 4 3 3 4 4 8 GAME 5 2 6 5 6 8 GAME 6 3 3 3 2 8 GAME 7 2 2 1 0 6 8 GAME 8 2 3 0 4 8 GAME 9 1 2 1 6 8 GAME 10 2 2 1 0 4 8 GAME 11 2 3 0 2 8 GAME 12 1 1 1 3 4 8 GAME 13 3 3 3 4 8 GAME 14 4 1 2 1 8 GAME 15 3 3 4 2 3 8 GAME 16 2 3 1 5 8 GAME 17 2 2 0...
output:
RQKBBNRN NRQBBKNR QRKBNNBR QRKNRBBN QRKRBBNN RQKBBNRN NRQBBKNR QRKBNNBR QRKRBBNN NRKRBBQN RQKBBNRN NRKBBQNR QRKRNBBN QRKBRNBN NRKRBBNQ RQKBBNRN NRQBBKNR QRKBNNBR QBRKBNNR QRKRBNNB RQKBBNRN NRKBBQNR QRKRBBNN QRKRBNNB NRKRBQNB RQKBBNRN NRQBBKNR QRKBNNBR QRKNRBBN NRKRBNQB RQKBBNRN NRKBBQNR QNNBBRKR RBB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #5:
score: 0
Accepted
time: 1549ms
memory: 3668kb
input:
GAME 1 3 0 2 0 2 8 GAME 2 2 0 2 1 2 8 GAME 3 1 3 2 4 1 8 GAME 4 3 0 0 1 8 GAME 5 2 0 3 4 1 8 GAME 6 1 2 4 2 8 GAME 7 2 1 4 3 2 8 GAME 8 2 0 3 0 1 8 GAME 9 1 4 0 2 8 GAME 10 3 3 0 1 8 GAME 11 3 1 5 1 8 GAME 12 2 2 3 6 8 GAME 13 2 0 4 1 3 8 GAME 14 2 0 4 1 2 8 GAME 15 1 3 4 3 2 8 GAME 16 2 1 3 1 1 8 G...
output:
RQKBBNRN NRQBBKNR BNRQKBRN QRKRBNNB QRKRBBNN RQNKRBBN RQKBBNRN NRKBBQNR RKNQNRBB QBRNBKRN QRKRBBNN RNQKRBBN RQKBBNRN RNBBNKRQ RBBNKRNQ QNRKNBBR QRKRBBNN RNNKRBBQ RQKBBNRN NRQBBKNR BNRQKBRN QRKRNBBN RQNKRNBB RQKBBNRN NRKBBQNR RKNQNRBB QRKNRNBB QRKRNBBN RNQKRNBB RQKBBNRN RNBBNKRQ RKNNQRBB RKQNNBBR RNN...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #6:
score: 0
Accepted
time: 1562ms
memory: 3656kb
input:
GAME 1 2 1 1 4 8 GAME 2 2 2 0 2 5 8 GAME 3 1 4 3 3 8 GAME 4 2 1 1 6 8 GAME 5 2 2 0 1 3 8 GAME 6 1 3 1 0 8 GAME 7 3 2 2 3 5 8 GAME 8 3 4 1 3 8 GAME 9 2 3 2 1 3 8 GAME 10 3 2 3 4 3 8 GAME 11 3 4 2 1 8 GAME 12 2 4 0 2 8 GAME 13 0 2 6 2 8 GAME 14 0 1 3 6 8 GAME 15 0 2 5 1 8 GAME 16 0 3 1 4 4 8 GAME 17 0...
output:
RQKBBNRN NRKBBQNR RBBNKQNR QRBKRNNB QRBKNBRN RQKBBNRN NRKBBQNR QNNBBRKR QRKNNBBR QRBKRBNN NRBKQBRN RQKBBNRN RNBBNKRQ NRQNBKRB QRBKRNNB NRBKNBRQ RQKBBNRN NRKBBQNR RBBNKQNR QRBKRNNB QRBKNNRB RQKBBNRN NRKBBQNR QNNBBRKR QRKNNBBR QRBKRBNN NRBKQNRB RQKBBNRN RNBBNKRQ RBBNKRNQ BBQNRKNR NRBKNQRB RQKBBNRN NRQ...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #7:
score: 0
Accepted
time: 1557ms
memory: 3628kb
input:
GAME 1 2 1 5 3 8 GAME 2 2 0 2 3 1 8 GAME 3 1 3 8 GAME 4 2 0 3 2 1 8 GAME 5 2 0 5 2 0 8 GAME 6 1 2 5 4 1 8 GAME 7 4 4 1 8 GAME 8 3 1 3 1 1 8 GAME 9 2 2 3 5 8 GAME 10 2 1 5 4 8 GAME 11 1 3 5 1 8 GAME 12 1 3 5 2 8 GAME 13 4 3 1 0 8 GAME 14 3 2 1 1 1 8 GAME 15 2 1 2 0 0 8 GAME 16 2 0 5 1 8 GAME 17 1 2 5...
output:
RQKBBNRN NRKBBQNR RBBNKQNR QRBKNRNB RBBQKRNN RQKBBNRN NRKBBQNR RKNQNRBB QBRNBKRN QRKNRNBB RBBNKRQN RQKBBNRN RNBBNKRQ RBBNKRNQ RQKBBNRN NRKBBQNR RKNQNRBB QRKNRNBB QRKRBBNN RBQNKRBN RQKBBNRN NRKBBQNR RKNQNRBB QRKRNBBN QRKRBNNB RBNQKRBN RQKBBNRN RNBBNKRQ RKNNQRBB QBRNKNBR QRKBBRNN RBNNKRBQ RQKBBNRN RQK...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #8:
score: 0
Accepted
time: 1566ms
memory: 3620kb
input:
GAME 1 2 3 3 3 3 8 GAME 2 2 4 5 2 8 GAME 3 1 1 0 2 1 8 GAME 4 0 4 1 3 8 GAME 5 0 3 3 2 8 GAME 6 0 2 3 5 8 GAME 7 1 0 4 0 3 8 GAME 8 1 0 5 0 8 GAME 9 0 3 4 0 8 GAME 10 3 2 1 2 2 8 GAME 11 2 1 1 0 1 8 GAME 12 1 3 4 2 1 8 GAME 13 1 0 4 1 2 8 GAME 14 0 1 2 1 8 GAME 15 0 2 0 0 8 GAME 16 1 0 6 2 8 GAME 17...
output:
RQKBBNRN NRKBBQNR RQNBBKNR QRNKBRNB QRKRNBBN QRNBKNBR RQKBBNRN NRKBBQNR QNRBKNBR QRKRBNNB NRQBKNBR RQKBBNRN RNBBNKRQ QNRKBRNB QRKNRBBN QRKRBBNN NRNBKQBR RQKBBNRN QBRNNKBR BBQRNKNR QRKRBBNN QRNNKBBR RQKBBNRN QBRNNKBR QNRNKRBB QRBNNKRB NRQNKBBR RQKBBNRN QBRNNKBR QRBKNBNR BRNNKBQR NRNQKBBR RQKBBNRN RNB...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #9:
score: 0
Accepted
time: 1543ms
memory: 3696kb
input:
GAME 1 1 1 2 4 3 8 GAME 2 0 2 3 2 8 GAME 3 1 1 0 0 2 8 GAME 4 1 0 3 4 3 8 GAME 5 1 0 4 3 2 8 GAME 6 0 3 2 0 1 8 GAME 7 0 2 5 4 8 GAME 8 1 1 1 3 2 8 GAME 9 0 1 0 2 8 GAME 10 0 3 4 3 8 GAME 11 1 0 3 3 3 8 GAME 12 0 2 2 2 8 GAME 13 3 1 2 1 1 8 GAME 14 3 1 2 0 8 GAME 15 2 0 2 4 1 8 GAME 16 4 3 5 1 8 GAM...
output:
RQKBBNRN RNBBNKRQ QNRKBRNB NBQRBNKR QRKRBBNN QBBRKNNR RQKBBNRN QBRNNKBR QRBKNBNR BRNNKBQR NBBRKQNR RQKBBNRN RNBBNKRQ QNRKBRNB QRKNRBBN QRBBKRNN NBBRKNQR RQKBBNRN RNBBNKRQ NBRNKRBQ QRNNKRBB QRKBRNBN QBNRKNBR RQKBBNRN RNBBNKRQ NBRNKRBQ QRKRNNBB QRKBRNBN NBQRKNBR RQKBBNRN QBRNNKBR QNRNKRBB QRBKRBNN QRK...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #10:
score: 0
Accepted
time: 1543ms
memory: 3616kb
input:
GAME 1 0 5 1 4 8 GAME 2 0 5 0 0 8 GAME 3 0 6 1 0 8 GAME 4 2 3 5 2 8 GAME 5 1 3 1 4 1 8 GAME 6 1 4 1 3 8 GAME 7 1 1 4 1 3 8 GAME 8 1 1 3 1 2 8 GAME 9 1 1 2 4 1 8 GAME 10 0 8 GAME 11 0 6 2 0 8 GAME 12 0 6 1 1 8 GAME 13 2 4 5 3 8 GAME 14 3 6 5 8 GAME 15 2 4 4 0 8 GAME 16 1 4 1 4 8 GAME 17 2 3 4 0 8 GAM...
output:
RQKBBNRN QBRNNKBR QRBKNBRN QRBBNKNR BBRQNKNR RQKBBNRN QBRNNKBR QRBKNBRN QRKBRNBN BBRNQKNR RQKBBNRN QBRNNKBR QRKRNBBN QRKBRNBN BBRNNKQR RQKBBNRN NRKBBQNR RQNBBKNR QNBBRKRN BQRBNKNR RQKBBNRN RNBBNKRQ RBBNKRNQ BBQNRKNR QRKRBNNB BNRBQKNR RQKBBNRN RNBBNKRQ NRQNBKRB QBBRNKNR BNRBNKQR RQKBBNRN RNBBNKRQ QNR...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Test #11:
score: 0
Accepted
time: 1563ms
memory: 3616kb
input:
GAME 1 5 4 2 8 GAME 2 4 2 6 0 8 GAME 3 3 3 2 1 1 8 GAME 4 3 2 2 3 2 8 GAME 5 2 2 4 2 1 8 GAME 6 2 2 5 2 8 GAME 7 2 3 2 3 2 8 GAME 8 2 3 3 2 2 8 GAME 9 1 2 1 2 8 GAME 10 0 3 1 3 8 GAME 11 0 2 4 1 1 8 GAME 12 0 2 3 6 8 GAME 13 2 3 2 4 8 GAME 14 2 4 3 2 8 GAME 15 1 3 1 1 1 8 GAME 16 0 4 2 4 8 GAME 17 0...
output:
RQKBBNRN RKNRBNQB QRKRBNNB RQNBBNKR RQKBBNRN RQKNBRNB RNBBQNKR QRKRNBBN RNQBBNKR RQKBBNRN NRQBBKNR QRKBNNBR QRKRBBNN QRKRBNNB RNNBBQKR RQKBBNRN NRQBBKNR QRBBNNKR QRKNNBBR QRKRBBNN RQNNBBKR RQKBBNRN NRKBBQNR QNNBBRKR QRNKBBRN QRKRBNNB RNQNBBKR RQKBBNRN NRKBBQNR QNNBBRKR QRKRBBNN RNNQBBKR RQKBBNRN NRK...
result:
ok (c) correct after 96 tests, max moves 6 (96 test cases)
Extra Test:
score: 0
Extra Test Passed