QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292746#7179. Fischer's Chess Guessing GameAlphaMale06TL 6ms7228kbC++142.4kb2023-12-28 12:33:322023-12-28 12:33:33

Judging History

This is the latest submission verdict.

  • [2023-12-28 12:33:33]
  • Judged
  • Verdict: TL
  • Time: 6ms
  • Memory: 7228kb
  • [2023-12-28 12:33:32]
  • Submitted

answer

#include <bits/stdc++.h>

/*
	Oce nas,
	koji si na nebesima,
	da se sveti ime Tvoje,
	da dodje carstvo Tvoje,
	da bude volja Tvoja,
	i na zemlji, kao i na nebu.
	
	Hleb nas nasusni daj nam danas,
	i oprosti nam dugove nase,
	kao sto i mi oprastamo duznicima svojim,
	i ne uvedi nas u iskusenje,
	no izbavi nas od zloga.
	
	Jer je Tvoje Carstvo,
	i sila, i slava,
	u vekove vekova.
	
	Amin.
*/

using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) (x).begin(), (x).end()

vector<string> v;
vector<pair<int, int>> cur;
vector<pair<int, int>> precalc;
vector<pair<int, int>> ncur;
int gas[960][960];

bool checkvalid(string s){
	int indb1, indb2, indk;
	indb1=-1;
	for(int i=0; i< 8; i++){
		if(s[i]=='B'){
			if(indb1==-1){
				indb1=i;
			}
			else indb2=i;
		}
		if(s[i]=='K'){
			indk=i;
		}
	}
	if(indb1%2==indb2%2)return 0;
	int cnt=0;
	for(int i=0; i< indk; i++){
		if(s[i]=='R')cnt++;
	}
	if(cnt==1)return 1;
	return 0;
}

int inter(int i, int j){
	int ans=0;
	for(int k=0; k< 8; k++){
		if(v[i][k]==v[j][k])ans++;
	}
	return ans;
}

void calcbest(){
	for(int i=0; i<cur.size(); i++){
		int cnt[9];
		for(int i=0; i< 9; i++)cnt[i]=0;
		for(int j=0; j<cur.size(); j++){
			cnt[gas[cur[i].S][cur[j].S]]++;
		}
		int mx=0;
		for(int i=0; i< 9; i++)mx=max(mx, cnt[i]);
		cur[i].F=mx;
	}
	sort(all(cur));
}


void solve(){
	cur=precalc;
	int ans=0;
	while(ans!=8){
		int ind=0;
		if(cur.size()==960){
			ind=rand()%959;
			ind++;
		}
		cout << v[cur[ind].S] << endl;
		cin >> ans;
		for(auto p : cur){
			if(gas[cur[ind].S][p.S]==ans){
				ncur.pb({0, p.S});
			}
		}
		cur=ncur;
		ncur.clear();
		calcbest();
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s="RRKNNQBB";
	sort(all(s));
	while(next_permutation(all(s))){
		if(checkvalid(s))v.pb(s);
	}
	for(int i=0; i< 960; i++){
		for(int j=0; j< 960; j++){
			gas[i][j]=inter(i, j);
		}
	}
	for(int i=0; i< 960; i++){
		cur.pb({0, i});
	}
	calcbest();
	precalc=cur;
	string partija;
	cin >> partija;
	while(partija!="END"){
		int mrs;
		cin >> mrs;
		solve();
		cin >> partija;
		cur.clear();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 7228kb

input:

GAME 1
1
4
3
4
8
END

output:

BNRKRNQB
RQKBBNNR
RBKQBNRN
RBNKBQNR
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 5 (1 test case)

Test #2:

score: -100
Time Limit Exceeded

input:

GAME 1
1
4
3
4
8
GAME 2
3
3
1
2
8
GAME 3
3
1
2
0
3
8
GAME 4
1
3
1
1
6
8
GAME 5
2
0
1
4
5
8
GAME 6
4
4
1
8
GAME 7
1
1
2
1
3
8
GAME 8
3
3
2
1
8
GAME 9
2
2
2
8
GAME 10
0
3
3
3
8
GAME 11
2
4
6
8
GAME 12
0
2
3
3
4
8
GAME 13
1
2
2
0
1
8
GAME 14
2
2
1
2
0
8
GAME 15
1
1
0
2
1
8
GAME 16
1
2
1
2
1
8
GAME 17
2...

output:

BNRKRNQB
RQKBBNNR
RBKQBNRN
RBNKBQNR
RKRBBQNN
NQRBBKNR
RBNNBKQR
QNNBRKBR
NBQRBKRN
RKRBBNQN
BNRKRBNQ
BRNQKBNR
BBRKQNRN
BNQNRKRB
RBBKNRNQ
RKRBBNNQ
NRKRNBBQ
RQBBNNKR
QBNRBNKR
RNBNKBQR
RKQBRNBN
RKRBQNBN
BRKBNNQR
QRNNBBKR
BNRQKNRB
RNKBQRBN
RKQBRNBN
RKRBNQBN
RKRQBNNB
RKNBBRNQ
RBKQBRNN
RKRBNNBQ
NBBRQKNR
NRK...

result: