-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomino_Tiles.cpp
More file actions
72 lines (64 loc) · 1.26 KB
/
Copy pathDomino_Tiles.cpp
File metadata and controls
72 lines (64 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve(){
int n;
cin>>n;
string a;
cin>>a;
a = " "+a;
bool ok =true;
int wish =-1;
bool okk = true;
bool okk1 = true;
// 检查奇数位置
for (int i=1;i<=n;i+=2){
if (a[i]!='?') {
okk = false;
}
if (wish==-1&&a[i]!='?') {
wish = (a[i]-'0')^1;
continue;
}
if (a[i]!='?'&&wish!=a[i]- '0') {
ok=false;
break;
}
if (wish != -1) wish ^= 1;
}
wish =-1;
// 检查偶数位置
for (int i=2;i<=n;i+=2) {
if (a[i]!='?') {
okk1 = false;
}
if (wish==-1&&a[i]!='?') {
wish = (a[i]-'0')^1;
continue;
}
if (a[i]!='?'&&wish!=a[i]- '0') {
ok=false;
break;
}
if (wish != -1) wish ^= 1;
}
if (!ok) {
cout<<0<<endl;
}else if (ok&&okk&&okk1) {
cout<<4<<endl;
}else if (ok&&(okk1||okk)) {
cout<<2<<endl;
}else if (ok&&!okk1&&!okk) {
cout<<1<<endl;
}
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int T =1;
cin>>T;
while(T--){
solve();
}
return 0;
}