QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368988#5250. Combination LocksNYCU_template#TL 359ms3584kbC++141.2kb2024-03-27 18:54:292024-03-27 18:54:29

Judging History

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

  • [2024-03-27 18:54:29]
  • 评测
  • 测评结果:TL
  • 用时:359ms
  • 内存:3584kb
  • [2024-03-27 18:54:29]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fi first
#define se second

int n, c;

string toggle(string s, int id){
	if(s[id] == '=') s[id] = '.';
	else s[id] = '=';
	return s;
}

bool Alice(string, set<string>&);

bool Bob(string now, set<string> &st){
	for(int i = 0; i < n; ++i){
		string s = toggle(now, i);
		if(st.find(s) == st.end()){
			st.insert(s);
			if(!Alice(s, st)){
				st.erase(s);
				return true;
			}
			st.erase(s);
		}
	}
	return false;
}

bool Alice(string now, set<string> &st){
	for(int i = 0; i < n; ++i){
		string s = toggle(now, i);
		if(st.find(s) == st.end()){
			st.insert(s);
			if(!Bob(s, st)){
				st.erase(s);
				return true;
			}
			st.erase(s);
		}
	}
	return false;
}

void solve()
{
	cin >> n >> c;
	string s1, s2; cin >> s1 >> s2;
	set<string> st;
	for(int i = 0; i < c; ++i){
		string s; cin >> s;
		st.insert(s);
	}
	string now = "";
	for(int i = 0; i < n; ++i){
		if(s1[i] == s2[i]) now += '=';
		else now += '.';
	}
	st.insert(now);
	if(Alice(now, st)) cout << "Alice\n";
	else cout << "Bob\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int T;
	cin >> T;
	while(T--)
	    solve();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

8
2 0
00
00
2 1
00
00
..
2 1
00
00
=.
2 2
00
00
..
=.
2 1
00
00
.=
2 2
00
00
..
.=
2 2
00
00
=.
.=
2 3
00
00
..
=.
.=

output:

Alice
Alice
Bob
Alice
Bob
Alice
Bob
Bob

result:

ok 8 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

20
4 4
4714
5245
..=.
..==
.==.
==..
4 1
2697
1438
.=..
4 5
9255
0677
...=
..==
=..=
==.=
====
4 12
3292
7326
...=
..=.
..==
.=..
.=.=
.==.
=...
=..=
=.==
==..
==.=
====
4 9
8455
2536
...=
..==
.=..
.=.=
.==.
.===
=...
==..
===.
4 12
5755
1517
...=
..=.
..==
.=..
.=.=
.===
=..=
=.=.
=.==
==..
==.=
=...

output:

Alice
Bob
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 20 lines

Test #4:

score: 0
Accepted
time: 359ms
memory: 3584kb

input:

20
5 30
99942
90170
.....
....=
...==
..=..
..=.=
..==.
..===
.=...
.=..=
.=.=.
.=.==
.==..
.==.=
.===.
.====
=...=
=..=.
=..==
=.=..
=.=.=
=.==.
=.===
==...
==..=
==.=.
==.==
===..
===.=
====.
=====
5 14
11760
95480
...=.
...==
..=..
..=.=
.=...
.=..=
.====
=....
=...=
=.=..
=.==.
==...
==.==
=====...

output:

Bob
Alice
Alice
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob

result:

ok 20 lines

Test #5:

score: -100
Time Limit Exceeded

input:

20
6 62
188256
588825
......
.....=
....=.
....==
...=..
...=.=
...==.
...===
..=...
..=..=
..=.=.
..=.==
..==..
..==.=
..===.
..====
.=....
.=...=
.=..=.
.=..==
.=.=..
.=.=.=
.=.==.
.=.===
.==..=
.==.=.
.==.==
.===..
.===.=
.=====
=.....
=....=
=...=.
=...==
=..=..
=..=.=
=..==.
=..===
=.=...
=.=.....

output:


result: