#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');
}
vector<vector<int>> g(N);
for (int i = 0; i < N; i++) {
if (target[i] != 'Y')
continue;
int x = -1;
for (int j = i - 1; j >= 0; j--) {
if (target[j] == 'X') {
x = j;
break;
}
}
int z = N;
for (int j = i + 1; j < N; j++) {
if (target[j] == 'Z') {
z = j;
break;
}
}
if (x == -1 || z == N)
continue;
for (int j = x + 1; j < z; j++) {
if (j == i)
continue;
g[j].push_back(i);
}
}
vector<vector<int>> dp(N);
vector<vector<int>> par(N);
for (int i = 0; i < N; i++) {
dp[i].resize(N, 0);
par[i].resize(N, 0);
dp[i][i] = 0;
par[i][i] = i;
}
for (int itv = 1; itv < N; itv++) {
for (int i = 0; i + itv < N; i++) {
int j = i + itv;
dp[i][j] = -1;
if (target[i] == 'X' && target[j] == 'Z') {
for (int k = i + 1; k < j; k++) {
if (target[k] == 'Y') {
if (dp[i][k - 1] + dp[k + 1][j] + 1 > dp[i][j]) {
dp[i][j] = dp[i][k - 1] + dp[k + 1][j] + 1;
par[i][j] = ~k;
}
}
}
}
for (int k = i; k < j; k++) {
if (dp[i][k] + dp[k + 1][j] > dp[i][j]) {
dp[i][j] = dp[i][k] + dp[k + 1][j];
par[i][j] = k;
}
}
}
}
vector<int> ord;
resolve(ord, dp, par, 0, N - 1);
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;
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
780 KB |
Output is correct |
2 |
Correct |
0 ms |
780 KB |
Output is correct |
3 |
Correct |
0 ms |
776 KB |
Output is correct |
4 |
Correct |
1 ms |
780 KB |
Output is correct |
5 |
Correct |
0 ms |
792 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 |
780 KB |
Output is correct |
10 |
Correct |
0 ms |
788 KB |
Output is correct |
11 |
Correct |
0 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |