#include "Anna.h"
#include <vector>
namespace {
int variable_example = 0;
}
void Anna(int N, std::vector<char> S) {
for (int i = 0; i < N; i++) {
if (S[i] == 'X') {
Send(0);
} else if (S[i] == 'Y') {
Send(1);
Send(0);
} else {
Send(1);
Send(1);
}
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int FT[100005];
void add(int idx, int amt) {
idx++;
while (idx < 100005) {
FT[idx] += amt;
idx += idx & -idx;
}
}
int sum(int idx) {
idx++;
int ret = 0;
while (idx > 0) {
ret += FT[idx];
idx -= idx & -idx;
}
return ret;
}
} // namespace
void Bruno(int N, int L, std::vector<int> A) {
set<int> active;
memset(FT, 0, sizeof(FT));
string target;
int ptr = 0;
while (ptr < L) {
if (A[ptr++] == 0)
target.push_back('X');
else if (A[ptr++] == 0)
target.push_back('Y');
else
target.push_back('Z');
}
bool done = false;
priority_queue<pair<int, int>> pq;
vector<int> prefX(N, -1);
for (int i = 0; i < N; i++) {
active.insert(i);
add(i, 1);
if (target[i] == 'X')
prefX[i] = i;
else
prefX[i] = i ? prefX[i - 1] : -1;
}
vector<int> suffZ(N, N);
for (int i = N - 1; i >= 0; i--) {
if (target[i] == 'Z')
suffZ[i] = i;
else
suffZ[i] = i == N - 1 ? N : suffZ[i + 1];
}
for (int i = 0; i < N; i++) {
if (target[i] == 'Y' && prefX[i] != -1 && suffZ[i] != N) {
int c = suffZ[i] - prefX[i] - 2;
pq.push({-c, i});
}
}
vector<int> ord;
while (!pq.empty()) {
auto ok = pq.top();
pq.pop();
if (target[ok.second] == '\0')
continue;
if (sum(suffZ[ok.second] - 1) - sum(prefX[ok.second]) - 1 !=
-ok.first) {
pq.push({-(sum(suffZ[ok.second] - 1) - sum(prefX[ok.second]) - 1),
ok.second});
continue;
}
auto it = active.upper_bound(prefX[ok.second]);
while (it != active.end() && *it < suffZ[ok.second]) {
int j = *it;
if (j == ok.second) {
++it;
continue;
}
target[j] = '\0';
add(j, -1);
ord.push_back(j);
it = active.erase(it);
}
target[ok.second] = '\0';
add(ok.second, -1);
ord.push_back(ok.second);
active.erase(ok.second);
}
for (int i = 0; i < N; i++) {
if (target[i] != '\0')
ord.push_back(i);
}
for (int x : ord)
Remove(x);
}
Compilation message
Anna.cpp:6:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
6 | int variable_example = 0;
| ^~~~~~~~~~~~~~~~
Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:37:10: warning: unused variable 'done' [-Wunused-variable]
37 | bool done = false;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1036 KB |
Output is correct |
2 |
Correct |
0 ms |
1036 KB |
Output is correct |
3 |
Correct |
1 ms |
1036 KB |
Output is correct |
4 |
Correct |
0 ms |
1036 KB |
Output is correct |
5 |
Correct |
1 ms |
1036 KB |
Output is correct |
6 |
Correct |
0 ms |
1036 KB |
Output is correct |
7 |
Correct |
1 ms |
1036 KB |
Output is correct |
8 |
Correct |
1 ms |
1048 KB |
Output is correct |
9 |
Correct |
1 ms |
1036 KB |
Output is correct |
10 |
Correct |
1 ms |
1036 KB |
Output is correct |
11 |
Correct |
1 ms |
1036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
84 ms |
12260 KB |
Partially correct |
2 |
Partially correct |
92 ms |
12268 KB |
Partially correct |
3 |
Partially correct |
89 ms |
12380 KB |
Partially correct |
4 |
Partially correct |
82 ms |
12200 KB |
Partially correct |
5 |
Partially correct |
81 ms |
12288 KB |
Partially correct |
6 |
Partially correct |
88 ms |
12092 KB |
Partially correct |
7 |
Partially correct |
87 ms |
12188 KB |
Partially correct |
8 |
Partially correct |
89 ms |
12356 KB |
Partially correct |
9 |
Partially correct |
85 ms |
12140 KB |
Partially correct |
10 |
Partially correct |
80 ms |
12148 KB |
Partially correct |
11 |
Partially correct |
83 ms |
12176 KB |
Partially correct |
12 |
Partially correct |
87 ms |
12284 KB |
Partially correct |
13 |
Partially correct |
84 ms |
10872 KB |
Partially correct |
14 |
Partially correct |
83 ms |
11996 KB |
Partially correct |
15 |
Partially correct |
69 ms |
13972 KB |
Partially correct |
16 |
Partially correct |
66 ms |
11340 KB |
Partially correct |
17 |
Partially correct |
79 ms |
14328 KB |
Partially correct |
18 |
Partially correct |
88 ms |
15972 KB |
Partially correct |
19 |
Partially correct |
76 ms |
15864 KB |
Partially correct |
20 |
Partially correct |
84 ms |
11256 KB |
Partially correct |
21 |
Partially correct |
88 ms |
11412 KB |
Partially correct |
22 |
Partially correct |
94 ms |
12268 KB |
Partially correct |
23 |
Partially correct |
97 ms |
11792 KB |
Partially correct |
24 |
Partially correct |
89 ms |
11708 KB |
Partially correct |
25 |
Partially correct |
77 ms |
15976 KB |
Partially correct |
26 |
Partially correct |
72 ms |
15872 KB |
Partially correct |
27 |
Partially correct |
87 ms |
15972 KB |
Partially correct |
28 |
Partially correct |
87 ms |
15980 KB |
Partially correct |
29 |
Partially correct |
90 ms |
15872 KB |
Partially correct |
30 |
Partially correct |
75 ms |
15920 KB |
Partially correct |
31 |
Partially correct |
81 ms |
16020 KB |
Partially correct |
32 |
Partially correct |
100 ms |
11992 KB |
Partially correct |
33 |
Partially correct |
99 ms |
11988 KB |
Partially correct |