QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291830 | #7179. Fischer's Chess Guessing Game | OAleksa | WA | 22ms | 3740kb | C++14 | 2.3kb | 2023-12-27 09:18:34 | 2023-12-27 09:18:36 |
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<int> g(N);
vector<char> sv = {'K', 'Q', 'N', 'N', 'B', 'B', 'R', 'R'};
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 i = 0;i < 8;i++)
r += (a[i] == b[i]);
return r;
};
string ans;
void resi(int r) {
for (int i = 0;i < N;i++) {
if (diff(perm[i], ans) != r)
g[i] = false;
}
int mn = 1e9;
for (int i = 0;i < N;i++) {
if (!g[i])
continue;
int mx = 0;
vector<int> cnt(10);
for (int j = 0;j < N;j++) {
if (!g[j])
continue;
mx = max(mx, ++cnt[diff(perm[i], perm[j])]);
}
if (mx < mn) {
mn = mx;
ans = perm[i];
}
}
}
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()));
int mx = 1e9;
for (int i = 0;i < 960;i++) {
vector<int> cnt(10);
int l = 0;
for (int j = 0;j < 960;j++)
l = max(l, ++cnt[diff(perm[i], perm[j])]);
if (l < mx) {
ans = perm[i];
mx = l;
}
}
while (true) {
string s;
cin >> s;
if (s == "GAME") {
for (int i = 0;i < N;i++)
g[i] = 1;
cin >> s;
int c = 0;
while (true) {
cout << ans << endl;
c++;
if (c == 6)
return 0;
int r;
cin >> r;
if (r == 8)
break;
resi(r);
}
}
else
break;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 3740kb
input:
GAME 1 2 2 1 8 END
output:
NRNBBKQR RNQNBBKR BBQRNKNR RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 4 (1 test case)
Test #2:
score: -100
Wrong Answer
time: 22ms
memory: 3640kb
input:
GAME 1 2 2 1 8 GAME 2 6 4 5 8 GAME 3 6 5 5 4 8 GAME 4 5 5 4 4 8 GAME 5 6 4 5 8 GAME 6 6 5 5 4 8 GAME 7 3 2 1 1 8 GAME 8 6 4 5 8 GAME 9 6 5 5 4 8 GAME 10 5 3 3 8 GAME 11 6 4 5 8 GAME 12 6 5 5 4 8 GAME 13 3 4 1 3 8 GAME 14 6 4 5 8 GAME 15 6 5 5 4 8 GAME 16 5 5 4 4 8 GAME 17 6 4 5 8 GAME 18 6 5 5 4 8 G...
output:
NRNBBKQR RNQNBBKR BBQRNKNR RKRBBQNN RKRBBQNN RKNBBQNR RKRQBBNN RKRBBNQN RKRBBNQN RKNBBNQR RKQBBNRN RKBBRNQN RKRBBNNQ RKRBBNNQ RKQBBNRN RKBBNNRQ RKNBBNQR RKRBQNBN RKRBQNBN RKNBQNBR RKRNQBBN RKRBNQBN RKRBNQBN RKNBNQBR RKQBNRBN RKBBNQRN RKRBNNBQ RKRBNNBQ RKNNQRBB QBRNKNBR RQBKNNRB RKRQBBNN RKRQBBNN RKN...
result:
wrong answer (i) illegal position "" (game 83, guess 1) (test case 83)