QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708938 | #7179. Fischer's Chess Guessing Game | tanph | RE | 1ms | 3600kb | C++20 | 2.8kb | 2024-11-04 09:53:05 | 2024-11-04 09:53:06 |
Judging History
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) {
v<string> clone = states;
string s; i32 huybeos;
while(true) {
cin >> s;
if(s == "END") break;
cin >> huybeos;
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;
if(c == 8) break;
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;
}
states = clone;
}
}
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: 100
Accepted
time: 1ms
memory: 3600kb
input:
GAME 1 0 0 5 8 END
output:
BBNNRKQR NNQRKRBB RKBBNQRN RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 4 (1 test case)
Test #2:
score: -100
Runtime Error
input:
GAME 1 0 0 5 8 GAME 2 1 0 4 2 8 GAME 3 0 0 3 8 GAME 4 0 1 2 4 8 GAME 5 0 1 1 4 8 GAME 6 0 1 3 8 GAME 7 0 0 3 5 8 GAME 8 2 1 1 1 2 8 GAME 9 1 1 0 4 1 8 GAME 10 0 1 2 8 GAME 11 1 2 2 2 3 8 GAME 12 2 2 0 2 2 1
output:
BBNNRKQR NNQRKRBB RKBBNQRN RKRBBQNN BBNNRKQR BNQRKRNB NQRBBNKR QRBBNNKR RKRBBNQN BBNNRKQR NNQRKRBB RKBBNQRN RKRBBNNQ BBNNRKQR NNQRKRBB NRKBBNRQ RKRQBNNB RKRBQNBN BBNNRKQR NNQRKRBB NRKBBNRQ RKBBQRNN RKRBNQBN BBNNRKQR NNQRKRBB NRKBBNRQ RKRBNNBQ BBNNRKQR NNQRKRBB RKBBNQRN RKRBBNNQ RKRQBBNN BBNNRKQR BBR...