# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1209857 | M_SH_O | Hidden Sequence (info1cup18_hidden) | C++20 | 2 ms | 428 KiB |
#include <bits/stdc++.h>
#include "grader.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
//#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 5000000000000000000
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(1488);
ll randll(ll l, ll r){
return uniform_int_distribution<ll>(l, r)(rng);
}
/*vi A;
bool isSubsequence(vi& a) {
ll x = 0;
for (int i : a) {
cout << i << ' ';
}
cout << endl;
if (a.empty()) return 1;
for (int i = 0; i < A.size(); i ++) {
if (A[i] == a[x]) x ++;
if (x == a.size()) return 1;
}
return 0;
}*/
vector < int > findSequence (int n) {
vi a;
for (int i = 0; i < n/2+1; i ++) {
a.pb(0);
}
if (isSubsequence(a)) {
a.clear();
ll k = 0;
for (int i = 0; i < n; i ++) {
a.pb(1);
if (!isSubsequence(a)) break;
}
k = a.size()-1;
vll b(k+1);
ll k1 = 0;
ll pos = -1;
for (int i = 0; i < k+1; i ++) {
a.clear();
for (int j = 0; j < i; j ++) {
a.pb(1);
}
ll x = 0;
for (int j = 0; j <(n-k)/2+1; j++) {
a.pb(0);
for (int i1 = 0; i1 < k-i; i1 ++) {
a.pb(1);
}
if (!isSubsequence(a)) break;
for (int i1 = 0; i1 < k-i; i1 ++) {
a.pop_back();
}
x ++;
}
b[i] = x;
if (x == (n-k)/2+1) pos = i;
k1 += x;
}
if (pos != -1) b[pos] += (n-k)-k1;
a.clear();
for (int i = 0; i < k+1; i ++) {
for (int j = 0; j < b[i]; j ++) {
a.pb(0);
}
if (i < k) a.pb(1);
}
return a;
}
else {
a.clear();
ll k = 0;
for (int i = 0; i < n; i ++) {
a.pb(0);
if (!isSubsequence(a)) break;
}
k = a.size()-1;
vll b(k+1);
ll k1 = 0;
ll pos = -1;
for (int i = 0; i < k+1; i ++) {
a.clear();
for (int j = 0; j < i; j ++) {
a.pb(0);
}
ll x = 0;
for (int j = 0; j <(n-k)/2+1; j++) {
a.pb(1);
for (int i1 = 0; i1 < k-i; i1 ++) {
a.pb(0);
}
if (!isSubsequence(a)) break;
for (int i1 = 0; i1 < k-i; i1 ++) {
a.pop_back();
}
x ++;
}
b[i] = x;
if (x == (n-k)/2+1) pos = i;
k1 += x;
}
if (pos != -1) b[pos] += (n-k)-k1;
a.clear();
for (int i = 0; i < k+1; i ++) {
//cout << b[i] << ' ';
for (int j = 0; j < b[i]; j ++) {
a.pb(1);
}
if (i < k) a.pb(0);
}
//cout << endl;
return a;
}
}
/*int main() {
speed;
srand(time(0));
ll n;
cin >> n;
vi a(n);
for (int i =0 ; i < n; i ++) {
cin >> a[i];
}
A = a;
vi res = findSequence(n);
for (int i : res) {
cout << i << ' ';
}
cout << endl;
}*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |