QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708928 | #7179. Fischer's Chess Guessing Game | tanph | RE | 0ms | 0kb | C++20 | 2.6kb | 2024-11-04 09:45:28 | 2024-11-04 09:45:29 |
answer
#include <bits/stdc++.h>
#include "random"
using namespace std;
using i16 = short int;
using i32 = int32_t;
using i64 = int64_t;
using ui16 = unsigned short int;
using ui32 = uint32_t;
using ui64 = uint64_t;
template<class T>
using v = vector<T>;
#define all(a) (a).begin(), (a).end()
#define open(x) freopen(#x ".inp", "r", stdin), freopen(#x ".out", "w", stdout)
template<class X, class Y> bool mimi(X &x, const Y &y) {if(x > y) {x = y; return 1;} return 0;}
template<class X, class Y> bool mama(X &x, const Y &y) {if(x < y) {x = y; return 1;} return 0;}
const i32 N = 2 * 1e5;
const i32 M = 1e9 + 7;
const i32 inf = 1e9 + 9;
const i64 infll = 1e18 + 18;
// mt19937_64 rng(static_cast<i32>(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()));
// i32 rand(i32 l, i32 r) {
// return uniform_int_distribution<i32>(l, r)(rng);
// }
string d = "RRNNBBKQ";
bool check(string &s) {
v<i32> pos(5, -1);
for(i32 i = 0; i < 8; i ++) {
if(s[i] == 'R') if(pos[0] == -1) pos[0] = i;
else pos[1] = i;
if(s[i] == 'B') if(pos[2] == -1) pos[2] = i;
else pos[3] = i;
if(s[i] == 'K') pos[4] = i;
}
if(pos[0] > pos[4] || pos[1] < pos[4]) return false;
if((pos[2] & 1) == (pos[3] & 1)) return false;
return true;
}
v<string> states;
i32 n = 960;
void sad(i32 testID) {
string s;
while(cin >> s) {
if(s[0] == 'E') break;
i32 c = 0, idx = 0;
while(c != 8) {
if(states.empty()) throw std::runtime_error("No solution");
idx = (idx + 1) % states.size();
string temp = states[idx];
cout << temp << endl;
cin >> c;
for(i32 j = states.size() - 1; j >= 0; j --) {
i32 cnt = 0;
for(i32 k = 0; k < 8; k ++)
if(states[j][k] == temp[k]) cnt ++;
// if(states[j] == "RKRBBQNN") cout << "Match: " << cnt << endl;
if(cnt != c) states.erase(states.begin() + j);
}
// cout << "Remaining: " << states.size() << endl;
}
}
}
i32 main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
sort(all(d));
do {
if(check(d)) states.push_back(d);
} while(next_permutation(all(d)));
states.resize(distance(states.begin(), unique(states.begin(), states.end())));
i32 t = 1;
// cin >> t;
for(i32 testID = 1; testID <= t; testID++) {
// cout << "Case #" << testID << ":\n";
sad(testID);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
GAME 1 0 1 3 1 3 2
output:
BBNNRKQR BNQRKRNB NQRBBNKR RBBKNNRQ RKRNNBBQ QRBBNKRN