QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703495#9537. Chinese Chessucup-team5657#WA 878ms4724kbC++205.4kb2024-11-02 17:53:212024-11-02 17:53:27

Judging History

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

  • [2024-11-02 17:53:27]
  • 评测
  • 测评结果:WA
  • 用时:878ms
  • 内存:4724kb
  • [2024-11-02 17:53:21]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;
using ull = unsigned long long;
const int inf = 0x3f3f3f3f;
const ll inf64 = 0x3f3f3f3f3f3f3f3fll;
int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(unsigned x) { printf("%u ", x); } void outln(unsigned x) { printf("%u\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
void out(ull x) { printf("%llu ", x); } void outln(ull x) { printf("%llu\n", x); }
template<typename T, typename U> void chkmax(T &a, const U &b) { if(b > a) a = b; } 
template<typename T, typename U> void chkmin(T &a, const U &b) { if(b < a) a = b; } 
bitset<540> F[90][90], msk[6];
int vis[90][90];
vector<pii> mov[6];
bool check(int x, int y) { return 0 <= x && x <= 9 && 0 <= y && y <= 8; }
void bfs(int x, int y, int t) {
	queue<pii> q; q.emplace(x, y);
	while(!q.empty()) {
		auto [x, y] = q.front(); q.pop();
		for(auto &[dx, dy] : mov[t]) {
			int nx = x + dx, ny = y + dy; 
			if(check(nx, ny) && !(t == 5 && !dx && x <= 4) && vis[nx][ny] > vis[x][y]) {
				vis[nx][ny] = vis[x][y] + 1;
				q.emplace(nx, ny);
			}
		}
	}
}
int flg;
int dfs(bitset<540> st, int L) { bitset<540> tmp;
	if(st.count() == 1) return 0;
	_rep(t,0,5) if((st & msk[t]).count() == st.count()) return 0;
	if(L >= 3) return inf;
	vector<pii> S;
	_rep(i,0,89) {
		int mx = 0, m2x = 0; 
		_rep(j,0,89) {
			if(tmp = st & F[i][j]; tmp.count() != st.count()) 
				chkmax(mx, tmp.count());
			else { m2x = 1; break; }
		}
		if(!m2x) S.emplace_back(mx, i);
	}
	sort(S.begin(), S.end());
	int mn = inf;
	for(int i = 0; i < min(60, int(S.size())); ++i) { int u = S[i].second, mx = 0;
		if(L <= 2) {
			int w;
			vector<pii> v; _rep(j,0,89) if(tmp = st & F[u][j], w = tmp.count(); w) v.emplace_back(w, j);
			sort(v.begin(), v.end(), greater<pii>());
			_rep(j,0,min(40, int(v.size()) - 1)) {
				chkmax(mx, dfs(st & F[u][v[j].second], L + 1));
				if(mx >= 3 - L - 1) break;
			}
		} else {
			_rep(j,0,89) {
				tmp = st & F[u][j]; int v = tmp.count(); if(v) {
					_rep(t,0,5) {
						int a = (tmp & msk[t]).count();
						if(a && a < v) mx = 100000000;
					}
				}
			}
		}
		chkmin(mn, mx); if(!mn) break;
	}
	return mn + 1;
}
int ans ;
void DOIT(bitset<540> st, int L) { bitset<540> tmp;
	_rep(t,0,5) {
		int cnt = 0;
		_rep(i,t * 90, (t + 1) * 90 - 1) cnt += st[i];
		if(cnt == st.count()) {
			printf("! ");
			if(t == 0) puts("J");
			if(t == 1) puts("M");
			if(t == 2) puts("S");
			if(t == 3) puts("X");
			if(t == 4) puts("C");
			if(t == 5) puts("B");
			fflush(stdout);
			exit(0);
		}
	}
	vector<pii> S;
	_rep(i,0,89) {
		int mx = 0, m2x = 0; 
		_rep(j,0,89) {
			if(tmp = st & F[i][j]; tmp.count() != st.count()) 
				chkmax(mx, tmp.count());
			else { m2x = 1; break; }
		}
		if(!m2x) S.emplace_back(mx, i);
	}
	sort(S.begin(), S.end());
	int mn = inf;
	for(int i = 0; i < min(60, int(S.size())); ++i) { int u = S[i].second, mx = 0;
		if(L <= 2) {
			int w;
			vector<pii> v; _rep(j,0,89) if(tmp = st & F[u][j], w = tmp.count(); w) v.emplace_back(w, j);
			sort(v.begin(), v.end(), greater<pii>());
			_rep(j,0,min(40, int(v.size()) - 1)) {
				chkmax(mx, dfs(st & F[u][v[j].second], L + 1));
				if(mx >= 3 - L - 1) break;
			}
		} else {
			_rep(j,0,89) {
				tmp = st & F[u][j]; int v = tmp.count(); if(v) {
					_rep(t,0,5) {
						int a = (tmp & msk[t]).count();
						if(a && a < v) mx = 100000000;
					}
				}
			}
		}
		if(mx == ans - L - 1) {
			printf("? %d %d\n", S[i].second / 9, S[i].second % 9); fflush(stdout);
			int u = in();
			DOIT(st & F[S[i].second][u == -1 ? 89 : u], L + 1); 
		}
	}
}
int main() { 
	mov[0] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; //J
	mov[1] = {{1, 2}, {-1, 2}, {1, -2}, {-1, -2}, {2, 1}, {-2, 1}, {2, -1}, {-2, -1}}; //M
	mov[2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; //S
	mov[3] = {{2, 2}, {-2, 2}, {2, -2}, {-2, -2}}; //X
	_rep(i,-9,9) if(i) mov[4].emplace_back(i, 0), mov[4].emplace_back(0, i); //C
	mov[5] = {{1, 0}, {0, 1}, {0, -1}}; //B
	_rep(t,0,5) _rep(i,0,9) _rep(j,0,8) {
		_rep(x,0,9) _rep(y,0,8) vis[x][y] = 89;
		vis[i][j] = 0, bfs(i, j, t);
		_rep(x,0,9) _rep(y,0,8) F[x * 9 + y][vis[x][y]][t * 90 + i * 9 + j] = 1;
	}
	_rep(t,0,5) _rep(j,t * 90,(t + 1) * 90 - 1) msk[t][j] = 1;
	bitset<540> st;
	// st.set();
	int n = in();
	_rep(i,1,n) {
		int x = in(), y = in(), z = x * 9 + y;
		_rep(j,0,5) st[j * 90 + z] = 1;
	}
	outln(ans = dfs(st, 0));
	DOIT(st, 0);
	return 0;
}

/* 
a list of keywords
clear empty push_back pop_back push pop top front back
emplace_back emplace push_front pop_front insert erase
find count set reset bitset map vector string multiset
first second iterator prev next deque multimap reverse
sort begin end list modify query init check calc prime
putchar getchar puts scanf printf max min swap replace
make_pair make_tuple numeric_limits auto function null
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 4676kb

input:

1
9 0
8

output:

1
? 1 8
! S

result:

ok number is guessed.

Test #2:

score: 0
Accepted
time: 99ms
memory: 4380kb

input:

4
2 1
2 3
2 5
2 7
12
9

output:

2
? 7 0
? 0 0
! J

result:

ok number is guessed.

Test #3:

score: 0
Accepted
time: 41ms
memory: 4448kb

input:

1
2 4
-1
1

output:

2
? 0 0
? 0 2
! X

result:

ok number is guessed.

Test #4:

score: 0
Accepted
time: 19ms
memory: 4444kb

input:

1
5 0
6

output:

1
? 3 6
! S

result:

ok number is guessed.

Test #5:

score: 0
Accepted
time: 24ms
memory: 4708kb

input:

1
6 0
6

output:

1
? 0 2
! S

result:

ok number is guessed.

Test #6:

score: 0
Accepted
time: 53ms
memory: 4420kb

input:

2
7 7
1 0
5
14

output:

2
? 7 2
? 0 0
! J

result:

ok number is guessed.

Test #7:

score: 0
Accepted
time: 271ms
memory: 4428kb

input:

5
8 6
1 3
0 5
2 4
0 2
10
2

output:

2
? 9 3
? 0 0
! J

result:

ok number is guessed.

Test #8:

score: 0
Accepted
time: 191ms
memory: 4424kb

input:

6
0 7
1 6
2 8
0 5
7 6
8 2
14
-1

output:

2
? 8 1
? 0 0
! B

result:

ok number is guessed.

Test #9:

score: 0
Accepted
time: 246ms
memory: 4516kb

input:

7
6 5
3 0
3 2
4 1
4 0
2 4
5 2
11
4

output:

2
? 7 8
? 0 0
! J

result:

ok number is guessed.

Test #10:

score: 0
Accepted
time: 343ms
memory: 4668kb

input:

8
3 3
2 5
6 2
7 4
1 4
3 0
2 4
3 4
6
4

output:

2
? 7 4
? 0 1
! J

result:

ok number is guessed.

Test #11:

score: 0
Accepted
time: 300ms
memory: 4712kb

input:

9
2 7
2 4
2 5
2 2
2 1
2 0
2 6
2 3
2 8
11
9

output:

2
? 8 2
? 0 0
! J

result:

ok number is guessed.

Test #12:

score: 0
Accepted
time: 713ms
memory: 4376kb

input:

10
4 0
0 0
5 0
7 0
8 0
1 0
6 0
9 0
2 0
3 0
9
-1

output:

2
? 9 0
? 0 1
! B

result:

ok number is guessed.

Test #13:

score: 0
Accepted
time: 303ms
memory: 4444kb

input:

9
1 8
1 2
1 5
1 6
1 3
1 4
1 0
1 1
1 7
11
8

output:

2
? 7 2
? 0 0
! J

result:

ok number is guessed.

Test #14:

score: 0
Accepted
time: 871ms
memory: 4384kb

input:

10
0 4
5 4
8 4
2 4
4 4
7 4
3 4
9 4
6 4
1 4
11
5

output:

2
? 9 1
? 0 0
! J

result:

ok number is guessed.

Test #15:

score: 0
Accepted
time: 372ms
memory: 4424kb

input:

9
4 6
4 5
4 7
4 4
4 1
4 3
4 0
4 8
4 2
11
12

output:

2
? 8 1
? 0 0
! J

result:

ok number is guessed.

Test #16:

score: 0
Accepted
time: 729ms
memory: 4448kb

input:

10
9 2
5 2
1 2
8 2
6 2
7 2
2 2
0 2
4 2
3 2
9
-1

output:

2
? 9 2
? 0 0
! B

result:

ok number is guessed.

Test #17:

score: 0
Accepted
time: 384ms
memory: 4428kb

input:

9
3 1
3 7
3 5
3 3
3 6
3 4
3 0
3 2
3 8
11
10

output:

2
? 9 2
? 0 0
! J

result:

ok number is guessed.

Test #18:

score: 0
Accepted
time: 716ms
memory: 4420kb

input:

10
5 1
8 1
6 1
4 1
3 1
0 1
2 1
7 1
9 1
1 1
9
-1

output:

2
? 9 1
? 0 0
! B

result:

ok number is guessed.

Test #19:

score: 0
Accepted
time: 295ms
memory: 4724kb

input:

9
1 6
1 4
1 3
1 7
1 8
1 5
1 2
1 1
1 0
11
8

output:

2
? 7 2
? 0 0
! J

result:

ok number is guessed.

Test #20:

score: 0
Accepted
time: 713ms
memory: 4376kb

input:

10
5 0
9 0
1 0
2 0
3 0
6 0
7 0
4 0
0 0
8 0
9
-1

output:

2
? 9 0
? 0 1
! B

result:

ok number is guessed.

Test #21:

score: 0
Accepted
time: 243ms
memory: 4708kb

input:

9
0 3
0 5
0 7
0 0
0 4
0 8
0 1
0 6
0 2
11
7

output:

2
? 6 2
? 0 0
! J

result:

ok number is guessed.

Test #22:

score: 0
Accepted
time: 715ms
memory: 4724kb

input:

10
1 0
9 0
4 0
2 0
8 0
7 0
5 0
3 0
0 0
6 0
9
-1

output:

2
? 9 0
? 0 1
! B

result:

ok number is guessed.

Test #23:

score: 0
Accepted
time: 302ms
memory: 4680kb

input:

9
1 8
1 2
1 7
1 0
1 4
1 6
1 1
1 5
1 3
11
8

output:

2
? 7 2
? 0 0
! J

result:

ok number is guessed.

Test #24:

score: 0
Accepted
time: 878ms
memory: 4424kb

input:

10
2 4
1 4
0 4
6 4
4 4
9 4
5 4
3 4
7 4
8 4
11
5

output:

2
? 9 1
? 0 0
! J

result:

ok number is guessed.

Test #25:

score: 0
Accepted
time: 246ms
memory: 4444kb

input:

9
0 2
0 7
0 5
0 4
0 0
0 3
0 1
0 6
0 8
11
7

output:

2
? 6 2
? 0 0
! J

result:

ok number is guessed.

Test #26:

score: 0
Accepted
time: 838ms
memory: 4688kb

input:

10
5 3
2 3
3 3
8 3
9 3
1 3
6 3
7 3
0 3
4 3
11
4

output:

2
? 9 0
? 0 0
! J

result:

ok number is guessed.

Test #27:

score: 0
Accepted
time: 798ms
memory: 4708kb

input:

50
7 5
9 2
0 4
9 3
8 4
8 2
7 2
6 4
4 4
0 0
1 7
1 1
1 5
2 0
9 8
9 0
3 1
7 8
8 6
5 0
7 3
8 5
2 6
4 8
3 5
6 8
0 8
5 7
4 6
1 6
3 8
5 6
3 0
5 3
0 7
5 1
3 4
0 1
7 6
2 3
4 3
5 5
8 1
0 3
6 5
9 5
5 8
7 4
6 3
2 7
4
-1
3

output:

3
? 9 3
? 2 6
? 7 5
! X

result:

ok number is guessed.

Test #28:

score: 0
Accepted
time: 787ms
memory: 4448kb

input:

49
4 2
8 0
2 4
9 5
8 1
7 8
0 2
4 7
3 0
1 3
6 6
0 8
8 3
5 8
2 2
1 0
6 0
2 6
0 5
9 2
7 0
4 4
8 8
9 6
5 0
6 8
9 4
7 6
9 0
2 7
4 6
7 7
0 1
4 0
6 7
2 8
8 2
3 2
3 1
3 4
5 4
7 3
5 6
5 2
1 8
3 3
1 7
0 3
4 3
3
6
5

output:

3
? 9 0
? 0 0
? 0 1
! M

result:

ok number is guessed.

Test #29:

score: 0
Accepted
time: 797ms
memory: 4504kb

input:

48
6 7
3 5
0 3
5 7
1 6
9 6
6 2
0 7
5 5
0 4
0 5
0 8
6 4
4 2
8 5
1 2
1 3
8 1
2 7
0 2
2 6
7 1
6 5
0 1
3 7
6 8
7 4
3 3
5 4
5 1
4 4
8 8
7 5
0 0
1 0
7 6
7 7
3 0
7 8
4 0
9 2
9 7
6 6
2 1
6 1
5 2
5 6
4 1
3
-1
7

output:

3
? 9 2
? 2 6
? 1 2
! S

result:

ok number is guessed.

Test #30:

score: 0
Accepted
time: 787ms
memory: 4420kb

input:

51
0 8
1 6
5 3
2 6
9 0
4 0
8 1
0 7
1 0
2 4
8 4
3 6
7 1
8 6
9 7
0 6
5 4
3 2
6 6
7 7
6 1
5 0
4 5
4 8
6 8
3 5
5 8
5 5
8 7
9 6
6 0
3 3
2 3
3 1
2 8
4 4
6 4
1 7
7 2
8 0
3 0
8 8
3 7
1 3
5 6
7 4
6 5
2 7
1 1
7 6
3 8
3
-1
6

output:

3
? 9 3
? 0 0
? 9 0
! B

result:

ok number is guessed.

Test #31:

score: 0
Accepted
time: 785ms
memory: 4504kb

input:

52
1 6
3 8
0 6
9 2
6 4
5 4
2 1
1 0
4 2
2 2
3 2
9 6
7 1
0 2
8 7
1 4
3 1
8 0
3 0
5 8
1 5
7 4
5 7
5 1
6 8
1 2
9 0
6 5
0 4
4 0
5 5
5 0
2 6
6 2
8 5
7 0
0 7
5 3
9 3
0 1
3 5
8 1
4 5
4 6
7 5
8 3
7 8
7 2
3 3
2 5
8 8
2 8
3
-1
4

output:

3
? 9 2
? 3 7
? 7 0
! X

result:

ok number is guessed.

Test #32:

score: -100
Wrong Answer
time: 789ms
memory: 4380kb

input:

89
3 1
7 3
3 0
3 5
0 0
1 3
1 1
3 3
8 8
7 7
2 4
7 0
9 3
2 0
3 7
6 6
7 2
7 1
4 4
2 8
1 2
9 4
9 2
3 8
9 5
6 5
3 4
8 0
2 1
0 4
4 2
1 5
4 7
4 3
7 8
5 6
0 8
0 2
8 7
9 0
5 8
9 8
5 4
0 6
0 5
5 5
7 6
5 0
6 0
6 1
1 0
5 2
8 6
7 5
4 5
9 1
1 4
8 4
4 8
4 6
9 7
1 6
5 3
8 5
9 6
3 6
0 1
6 8
1 8
1 7
4 0
0 3
6 7
0 7
2...

output:

3
? 9 0
? 2 4
? 7 6
? 9 2

result:

wrong answer out of query limit m(3).