QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640409 | #7179. Fischer's Chess Guessing Game | Pedro_Sim | TL | 2ms | 3876kb | C++20 | 2.6kb | 2024-10-14 11:54:07 | 2024-10-14 11:54:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rp(i,a,b) for(int i=a;i<b;i++)
vector<string> resp;
// Function to verify if the string is valid based on the problem constraints
bool veri(string &t) {
int te = -1;
rp(i, 0, 8) {
if(te >= 0 && t[i] == 'B' && (i % 2) == (te % 2))
return false;
else if(t[i] == 'B')
te = i;
}
rp(i, 0, 8) {
if(t[i] == 'K') {
bool flag1 = true, flag2 = true;
rp(j, 0, i) if(t[j] == 'R') flag1 = false;
rp(j, i, 8) if(t[j] == 'R') flag2 = false;
if(flag1 || flag2) return false;
break;
}
}
return true;
}
void solvetask() {
int n;
cin >> n;
vector<string> current_state = resp;
string best_guess;
for(int turn = 0; turn < 10; ++turn) {
int max_reduction = 0;
string selected_guess;
for (auto &guess : current_state) {
vector<int> bins(9, 0);
for (auto &candidate : current_state) {
int matches = 0;
for (int k = 0; k < 8; ++k)
if (guess[k] == candidate[k])
++matches;
bins[matches]++;
}
int largest_bin = *max_element(bins.begin(), bins.end());
if (largest_bin < max_reduction || max_reduction == 0) {
max_reduction = largest_bin;
selected_guess = guess;
}
}
cout << selected_guess << endl;
fflush(stdout);
int correct_positions;
cin >> correct_positions;
if (correct_positions == 8)
break;
vector<string> new_state;
for (auto &candidate : current_state) {
int matches = 0;
for (int k = 0; k < 8; ++k)
if (candidate[k] == selected_guess[k])
++matches;
if (matches == correct_positions)
new_state.push_back(candidate);
}
current_state = new_state;
}
}
void pre_cal() {
string temp = "BBQKNNRR";
sort(temp.begin(), temp.end());
do {
if(veri(temp))
resp.push_back(temp);
} while(next_permutation(temp.begin(), temp.end()));
}
int main() {
cin.tie(0)->sync_with_stdio(0);
string t;
pre_cal();
while (true) {
cin >> t;
if (t == "END")
return 0;
solvetask();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3876kb
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
Time Limit Exceeded
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...