QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410094#7179. Fischer's Chess Guessing Gameec1117TL 26ms3740kbC++143.0kb2024-05-13 12:38:292024-05-13 12:38:29

Judging History

你现在查看的是最新测评结果

  • [2024-05-13 12:38:29]
  • 评测
  • 测评结果:TL
  • 用时:26ms
  • 内存:3740kb
  • [2024-05-13 12:38:29]
  • 提交

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");
		}

		vi tmp=*cur.begin();
		int MN = MOD;
		trav(y,cur) {
			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;
				tmp = y;
			}
		}
		
		// 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(-1);
}

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: 26ms
memory: 3740kb

input:

GAME 1
4
3
3
3
8
END

output:

RQKBBNRN
RQKNBRNB
RNKRBBQN
RBQNBKRN
RKRBBQNN

result:

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

Test #2:

score: -100
Time Limit Exceeded

input:

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

output:

RQKBBNRN
RQKNBRNB
RNKRBBQN
RBQNBKRN
RKRBBQNN
RQKBBNRN
RNKBBNQR
RBKRBNQN
RKRBBNQN
RQKBBNRN
RQKNBRNB
RNKRBBQN
RKRBBNNQ
RQKBBNRN
RQKNBRNB
RNBBKQRN
BQNBRKRN
RKRBQNBN
RQKBBNRN
NRBBQKRN
RKNBQNBR
RNBBKNQR
RKRBNQBN
RQKBBNRN
NRBBQKRN
RNKQRBBN
RBNKBRQN
RKRBNNBQ
RQKBBNRN
NRBBQKRN
RNKQRBBN
RNKBNQBR
RKRQBBNN
RQK...

result: