# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102667 | IOrtroiii | Hidden Sequence (info1cup18_hidden) | C++14 | 163 ms | 412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifndef F4F
#include "grader.h"
#endif
using namespace std;
int cnt[205];
vector<int> a;
#ifdef F4F
bool isSubsequence(vector<int> nw) {
int ptr = 0;
for (int v : a) {
if (ptr < nw.size() && v == nw[ptr]) {
++ptr;
}
}
return ptr == nw.size();
}
#endif
vector<int> findSequence(int n) {
int lim = (n / 2) + 1;
int num = -1, len = -1;
for (int t = 0; t < 2; ++t) {
vector<int> nw;
for (int i = 1; i <= lim; ++i) {
nw.push_back(t);
if (!isSubsequence(nw)) {
num = t;
len = i - 1;
break;
}
}
}
cnt[len] = n - len;
for (int i = 0; i < len; ++i) {
int x = i, y = len - 1 - i;
int z = 0, t = 0;
while (x + t < lim) {
vector<int> nw;
for (int j = 0; j <= x; ++j) nw.push_back(num);
for (int j = 0; j < t; ++j) nw.push_back(num ^ 1);
if (!isSubsequence(nw)) {
break;
}
++t;
}
while (y + z < lim) {
vector<int> nw;
for (int j = 0; j < z; ++j) nw.push_back(num ^ 1);
for (int j = 0; j <= y; ++j) nw.push_back(num);
if (!isSubsequence(nw)) {
break;
}
++z;
}
--z, --t;
if (x + t <= y + z) {
cnt[i] = n - len - t;
} else {
cnt[i] = z;
}
}
for (int i = len; i > 0; --i) cnt[i] -= cnt[i - 1];
vector<int> ans;
for (int i = 0; i < len; ++i) {
for (int j = 0; j < cnt[i]; ++j) ans.push_back(num ^ 1);
ans.push_back(num);
}
for (int i = 0; i < cnt[len]; ++i) ans.push_back(num ^ 1);
return ans;
}
#ifdef F4F
int main() {
int n;
cin >> n;
a.resize(n);
for (int &x : a) cin >> x;
auto nw = findSequence(n);
assert(nw == a);
}
#endif
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |