QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410112 | #7179. Fischer's Chess Guessing Game | ec1117 | TL | 24ms | 3784kb | C++14 | 3.1kb | 2024-05-13 13:19:47 | 2024-05-13 13:19:48 |
Judging History
answer
//https://qoj.ac/contest/1356/problem/7179
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define For(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define Rof(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if (sizeof...(t)) cerr << ", ";
DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
set<vi> totStates;
map<int, char> M = {{0,'R'}, {1,'B'}, {2,'N'}, {3,'K'}, {4,'Q'}};
string ts(vi v) {
string ret = "";
trav(x,v) {
ret += M[x];
}
return ret;
}
int diffs(vi a, vi b) {
int cnt = 0;
For(i,8)if(a[i]==b[i]) cnt++;
return cnt;
}
void solve() {
vector<vi> cur;
trav(x,totStates)cur.pb(x);
For(i,6) {
if(sz(cur)==0) {
dbg("ERR");
return;
}
if(sz(cur)==1) {
dbg("CORRECT");
}
vector<vi> oks;
vi tmp=*cur.begin();
int MN = MOD;
trav(y,totStates) {
vi cnts(8,0);
int mx = 0;
trav(x,cur) cnts[diffs(x,y)]++;
For(i,8) mx = max(mx, cnts[i]);
if(mx < MN) {
MN = mx;
oks.clear();
oks.pb(y);
} else if(mx==MN) {
oks.pb(y);
}
}
tmp = oks[rng()% sz(oks)];
// if(i>=4 && sz(cur) <= 8) {
// trav(x,cur) {
// set<int> tmps;
// trav(y,cur) tmps.insert(diffs(y,x));
// if(sz(tmps)==sz(cur)) {
// dbg("OK");
// tmp = x;
// }
// }
// }
cout << ts(tmp) << endl;
int x; cin>>x;
if(x==8) {
return;
}
vector<vi> news;
trav(y,cur) if(diffs(y,tmp)==x) {
news.pb(y);
}
cur = news;
}
assert(false);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
vi v = {0,0,1,1,2,2,3,4};
while(next_permutation(all(v))) {
int L =-1, R=-1, M=-1;
For(i,8) if(v[i]==0) {
L=i;
break;
}
Rof(i,8) if(v[i]==0) {
R=i;
break;
}
For(i,8) if(v[i]==3) {
M=i;
break;
}
if(M<L || M>R) continue;
vi v2;
For(i,8)if(v[i]==1) {
v2.pb(i%2);
}
assert(sz(v2)==2);
if((v2[0]^v2[1])==0) continue;
totStates.insert(v);
}
// cout <<sz(totStates) << endl;
// trav(x,totStates) {
// cout << ts(x) << endl;
// }
assert(sz(totStates) == 960);
while(true) {
string S;
getline(cin,S);
if(S=="END") {
break;
}
solve();
getline(cin,S);
}
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 24ms
memory: 3784kb
input:
GAME 1 4 2 6 8 END
output:
RQKBBNRN RNBBKNQR RKRNBQNB RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 4 (1 test case)
Test #2:
score: -100
Time Limit Exceeded
input:
GAME 1 4 2 6 8 GAME 2 5 5 1 8 GAME 3 1 0 3 4 5 8 GAME 4 1 4 4 1 8 GAME 5 2 3 4 2 8 GAME 6 2 2 5 2 8 GAME 7 1 4 2 4 8 GAME 8 1 3 3 5 8 GAME 9 2 2 4 2 2 8 GAME 10 3 2 3 3 1 8 GAME 11 3 1 1 2 2 8 GAME 12 2 2 1 2 0 8 GAME 13 2 0 5 2 1 8 GAME 14 4 1 4 5 8 GAME 15 0 5 3 2 8 GAME 16 2 0 2 6 3 8 GAME 17 2 0...
output:
RQKBBNRN RNBBKNQR RKRNBQNB RKRBBQNN RQKBBNRN RKNRBNQB NQNRBKRB RKRBBNQN NRBBNKQR BRNNKBQR NQRKBRNB RKNBBRQN RKNBBQNR RKRBBNNQ NRNBBKQR RKNBBQRN RKBNQNRB BNRNKQRB RKRBQNBN NRBBNKQR RNBBQKRN RQKBNNBR QNRBBKNR RKRBNQBN NRBBNKQR RNBBQKRN RKBBRNNQ BRQBKNRN RKRBNNBQ NRNBBKQR RKNBBQRN BNRQKNRB RBQKBRNN RKR...