-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
62 lines (59 loc) · 1.19 KB
/
D.cpp
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
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3;
#define index indices
int a[maxn];
deque <int> Q;
int n, k;
int add(int id) {
cout << "? " << id << endl;
string s;
cin >> s;
return s == "Y" ? true : false;
}
void clear() {
cout << "R" << endl;
Q.clear();
}
vector <int> index[maxn];
int block[maxn];
bool del[maxn];
int main() {
cin >> n >> k;
int size = max(1, k / 2);
int noBlock = n / size;
for(int i = 1; i <= n; i++) {
block[i] = (i - 1) / size + 1;
index[block[i]].push_back(i);
}
for(int i = 1; i <= 2 * size && i <= n; i++) {
del[i] = add(i);
}
clear();
for(int i = 3; i <= noBlock; i++) {
for(int j = 1; j < i; j += 2) {
for(int k : index[j]) {
if(!del[k]) {
del[k] = add(k);
}
}
for(int k : index[i]) {
if(!del[k]) {
del[k] = add(k);
}
}
for(int k : index[j + 1]) {
if(j + 1 < i && !del[k]) {
del[k] = add(k);
}
}
clear();
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += (del[i] == false);
}
cout << "! " << ans << endl;
return 0;
}