QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292093#7179. Fischer's Chess Guessing GameOAleksaWA 37ms3676kbC++142.3kb2023-12-27 17:57:172023-12-27 17:57:17

Judging History

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

  • [2023-12-27 17:57:17]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:3676kb
  • [2023-12-27 17:57:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 960;
vector<int> g(N);
vector<char> sv = {'K', 'Q', 'R', 'R', 'B', 'B', 'N', 'N'};
vector<string> perm;
int good(vector<char> ord) {
	int x = -1, y = -1, z = -1, b = -1, a = -1;
	for (int i = 0;i < 8;i++) {
		if (ord[i] == 'K')
			z = i;
		else if (ord[i] == 'B') {
			if (x == -1)
				x = i;
			else
				y = i;
		}
		else if (ord[i] == 'R') {
			if (a == -1)
				a = i;
			else
				b = i;
		}
	}
	return z < b && z > a && x % 2 != y % 2;
};
int diff(int i, int j) {
	int r = 0;
	for (int x = 0;x < 8;x++)
		r += (perm[i][x] == perm[j][x]);
	return r;
};
int ans;

void go(int r) {
	for (int i = 0;i < N;i++) {
		if (diff(i, ans) != r)
			g[i] = 0;
	}
	int mn = 1e9;
	for (int i = 0;i < N;i++) {
		if (!g[i])
			continue;
		vector<int> cnt(10);
		for (int j = 0;j < N;j++) {
			if (!g[j])
				continue;
			++cnt[diff(i, j)];
		}
		int mx = *max_element(cnt.begin(), cnt.end());
		if (mx < mn) {
			mn = mx;
			ans = i;
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
  cout.tie(nullptr); 
  cin.tie(nullptr);
  //freopen("newbarn.in", "r", stdin);
  //freopen(newbarn.out", "w", stdout);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	vector<int> order(8);
  	iota(order.begin(), order.end(), 0);
  	map<string, int> bio;
  	do {
  		vector<char> t;
  		for (int i = 0;i < 8;i++)
  			t.push_back(sv[order[i]]);
  		if (good(t)) {
  			string s;
  			for (auto x : t)
  				s += x;
  			if (bio[s])
  				continue;
  			bio[s] = 1;
  			perm.push_back(s);
  		}
  	} while (next_permutation(order.begin(), order.end()));
  	assert(perm.size() == N);
  	int mx = 1e9;
		int ans1;
  	for (int i = 0;i < N;i++) {
  		vector<int> cnt(10);
  		int l = 0;
  		for (int j = 0;j < N;j++) 
  			l = max(l, ++cnt[diff(i, j)]);
  		if (l < mx) {
  			ans1 = i;
  			mx = l;
  		}
  	}
  	while (true) {
  		string s;
  		cin >> s;
  		if (s == "GAME") {
  			ans = ans1;
  			for (int i = 0;i < N;i++)
  				g[i] = 1;
  			cin >> s;
  			int c = 0;
  			while (true) {
  				cout << perm[ans] << endl;
  				c++;
  				int r;
  				cin >> r;
  				if (r == 8 || c > 6)
  					break;
  				go(r);
  			}
  		}
  		else
  			break;
  	}
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 3564kb

input:

GAME 1
4
3
3
8
END

output:

RQKBBNRN
RQKNBRNB
QRKBBNNR
RKRBBQNN

result:

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

Test #2:

score: 0
Accepted
time: 37ms
memory: 3616kb

input:

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

output:

RQKBBNRN
RQKNBRNB
QRKBBNNR
RKRBBQNN
RQKBBNRN
RKNBBQRN
RBKNBQRN
RKRBBNQN
RQKBBNRN
RQKNBRNB
QRKBBNNR
QRKNBBRN
RKRBBNNQ
RQKBBNRN
RQKNBRNB
RNBBKQRN
BQNBRKRN
RKRBQNBN
RQKBBNRN
NRBBQKRN
RKNBQNBR
QRNBBNKR
RKQBNRBN
RKRBNQBN
RQKBBNRN
NRBBQKRN
RKNRBBQN
RKQBNNBR
RKRBNNBQ
RQKBBNRN
NRBBQKRN
RKNRBBQN
RKRQBBNN
RQK...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #3:

score: 0
Accepted
time: 22ms
memory: 3676kb

input:

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

output:

RQKBBNRN
RQKNBRNB
QRKBBNNR
RKQBBNNR
RQKBBNRN
NRBBQKRN
RKNRBBQN
RKNBBQNR
RQKBBNRN
RQKNBRNB
RKNQBBRN
RQBKNBRN
RKNBBNQR
RQKBBNRN
NRBBQKRN
RKNRBBQN
RKQBNNBR
RQKBBNRN
NRBBQKRN
RKNBQNBR
RQKBBNRN
RKBBNQNR
RNBBNQKR
RKNBNQBR
RQKBBNRN
RKBBNQNR
RKNRBQNB
RKQNBBNR
RQKBBNRN
RKBBNQNR
RKNRBQNB
RKBRQNNB
RKNQBBNR
RQK...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #4:

score: -100
Wrong Answer
time: 23ms
memory: 3620kb

input:

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

output:

RQKBBNRN
NRBBQKRN
RKNBQNBR
BQRKNBRN
QRKRBBNN
RQKBBNRN
NRBBQKRN
RBBKNQRN
BRKNQNRB
NQNRBKRB
NRKRBBQN
RQKBBNRN
RKBBNQNR
BRKNNBRQ
BRKRQBNN
QRKRNBBN
NRKRBBNQ
RQKBBNRN
NRBBQKRN
RKNRBBQN
RKQBNNBR
QRKRBNNB
RQKBBNRN
RKBBNQNR
RNKNRQBB
RKNQRBBN
NRKRBQNB
RQKBBNRN
NRBBQKRN
RKNBQNBR
BQRBKRNN
RNQNBKRB
NRKRBNQB
RQK...

result:

wrong answer (i) too many guesses in game 42, pos = ps