# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
254328 | Osama_Alkhodairy | Hidden Sequence (info1cup18_hidden) | C++17 | 11 ms | 256 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>
#include "grader.h"
//~ #include "grader.cpp"
using namespace std;
int n;
vector <int> compress(vector <int> &a){
vector <int> ret;
int n = a.size();
int cur = -1;
while(cur < n - 1){
int x = cur + 1, y = cur + 1;
while(x < n && a[x] != 0) x++;
while(y < n && a[y] != 1) y++;
assert(x < n || y < n);
if(y == n || (x < n && x > y)){
assert(x < n);
ret.push_back(0);
cur = x;
}
else{
ret.push_back(1);
cur = y;
}
}
return ret;
}
vector <int> findSequence(int N){
n = N;
vector <int> ones, zeros;
int z = 0, o = 0;
while(true){
ones.push_back(1);
zeros.push_back(0);
if(isSubsequence(zeros) == 0){
z = zeros.size() - 1;
o = n - z;
break;
}
if(isSubsequence(ones) == 0){
o = ones.size() - 1;
z = n - o;
break;
}
}
vector <int> a;
while((int)a.size() < n){
if(z == 0){
a.push_back(1);
continue;
}
if(o == 0){
a.push_back(0);
continue;
}
vector <int> g = a;
g.push_back(0);
g = compress(g);
for(int j = 0 ; j < o ; j++){
g.push_back(1);
}
vector <int> h = a;
h.push_back(1);
h = compress(h);
for(int j = 0 ; j < z ; j++){
h.push_back(0);
}
int c;
if(g.size() < h.size()){
if(isSubsequence(g)) c = 0;
else c = 1;
}
else{
if(isSubsequence(h)) c = 1;
else c = 0;
}
a.push_back(c);
if(c == 0) z--;
else o--;
}
return a;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |