# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1174632 | browntoad | Hidden Sequence (info1cup18_hidden) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#ifdef TOAD
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#else
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#endif // TOAD
const ll maxn = 1e3+5;
const int iinf = 1e9+5;
int n;
bool is_sub(string a, string b){
int ptr = 0;
REP(i, SZ(b)){
bool fnd = 0;
while(ptr < SZ(a)){
if (a[ptr] == b[i]){
fnd = 1;
ptr++;
break;
}
ptr++;
}
if (!fnd) return 0;
}
return 1;
}
string conv(int a, int nm){
string ret;
REP(i, nm){
if (a & (1<<i)) ret += '1';
else ret += '0';
}
return ret;
}
vector<int> findSequence(int n){
vector<string> puss;
REP(i, (1<<n)){
puss.pb(conv(i, n));
}
while(SZ(puss) > 1){
int mn = iinf;
string ret;
REP1(nm, n/2+2){
REP(j, (1<<nm)){
int suc = 0, fal = 0;
REP(k, SZ(puss)){
if (is_sub(puss[k], conv(j, nm))) suc++;
else fal++;
}
if (abs(suc-fal) < mn){
mn = abs(suc-fal);
ret = conv(j, nm);
}
}
}
vector<int> pp;
REP(i, SZ(ret)) pp.pb(ret[i] == '1');
bool qret = isSubsequence(pp);
vector<int> tmp;
REP(k, SZ(puss)){
if (is_sub(puss[k], conv(j, nm)) == qret){
tmp.pb(puss[k]);
}
}
puss = tmp;
}
vector<int> ret;
REP(i, SZ(puss[0])) ret.pb(puss[0][i] == '1');
return ret;
//cout<<mn<<endl;
//for (auto pp:ret) cout<<pp<<endl;
}
/*
signed main(){
IOS();
int n; cin>>n;
}
*/
/*
2 3
2 4 3
5 7 5
*/