#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 {
void resolve(vector<int> &ord, vector<vector<int>> &dp,
vector<vector<int>> &par, int l, int r) {
if (l > r)
return;
if (l == r) {
ord.push_back(l);
return;
}
if (par[l][r] >= 0) {
resolve(ord, dp, par, l, par[l][r]);
resolve(ord, dp, par, par[l][r] + 1, r);
} else {
resolve(ord, dp, par, l, ~par[l][r] - 1);
if (find(ord.begin(), ord.end(), l) != ord.end())
ord.erase(find(ord.begin(), ord.end(), l));
resolve(ord, dp, par, ~par[l][r] + 1, r);
if (find(ord.begin(), ord.end(), r) != ord.end())
ord.erase(find(ord.begin(), ord.end(), r));
ord.push_back(~par[l][r]);
ord.push_back(l);
ord.push_back(r);
}
}
} // namespace
void Bruno(int N, int L, std::vector<int> A) {
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;
vector<int> ord;
int chosen = -1;
do {
vector<int> prefX(N, -1);
for (int i = 0; i < N; i++) {
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];
}
int mn = 1e9;
chosen = -1;
for (int i = 0; i < N; i++) {
if (target[i] == 'Y' && prefX[i] != -1 && suffZ[i] != N) {
int c = 0;
for (int j = prefX[i] + 1; j <= suffZ[i] - 1; j++) {
if (j == i)
continue;
if (target[j] != '\0')
c++;
}
if (c < mn) {
mn = c;
chosen = i;
}
}
}
if (chosen != -1) {
for (int j = prefX[chosen] + 1; j <= suffZ[chosen] - 1; j++) {
if (j == chosen)
continue;
if (target[j] != '\0') {
ord.push_back(j);
target[j] = '\0';
}
}
ord.push_back(chosen);
target[chosen] = '\0';
}
} while (chosen != -1);
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:41:10: warning: unused variable 'done' [-Wunused-variable]
41 | bool done = false;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
792 KB |
Output is correct |
2 |
Correct |
0 ms |
792 KB |
Output is correct |
3 |
Correct |
0 ms |
796 KB |
Output is correct |
4 |
Correct |
0 ms |
792 KB |
Output is correct |
5 |
Correct |
0 ms |
1044 KB |
Output is correct |
6 |
Correct |
0 ms |
792 KB |
Output is correct |
7 |
Correct |
0 ms |
780 KB |
Output is correct |
8 |
Correct |
0 ms |
792 KB |
Output is correct |
9 |
Correct |
0 ms |
792 KB |
Output is correct |
10 |
Correct |
0 ms |
792 KB |
Output is correct |
11 |
Correct |
0 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2012 ms |
4908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |