QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74698 | #5434. Binary Substrings | heno239 | TL | 9ms | 11760kb | C++17 | 9.1kb | 2023-02-03 12:54:11 | 2023-02-03 12:54:13 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
using ld = double;
//typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
//-----------------------------------------
void expr2(int m) {
vector<int> nex(1 << (m-1));
int ad = 1 << (m - 1);
rep(i, 1 << (m - 1)) {
nex[i] = (i + ad) / 2;
}
vector<bool> used(nex.size());
int cnt = 0;
rep(i, nex.size()) {
if (used[i])continue;
cnt++;
int cur = i;
while (!used[cur]) {
used[cur] = true;
cur = nex[cur];
}
}
cout << cnt << "\n";
}
void expr3(int m) {
vector<int> res;
vector<bool> used(1 << m);
int cur = (1 << (m - 1)); used[cur] = true;
rep(i, m) {
if (cur & (1 << i))res.push_back(1);
else res.push_back(0);
}
int tmp = 0;
vector<bool> sused(1 << (m - 1));
int len;
auto upd = [&](int x) {
if (tmp == (1 << (m - 1)))return;
if (!sused[x]) {
sused[x] = true;
tmp++;
if (tmp == (1 << (m - 1)))len = res.size();
}
};
upd(0);
upd(1 << (m - 2));
int ad = 1 << (m - 1);
while (true) {
int nex = cur / 2;
if (!used[nex + ad]) {
res.push_back(1);
cur = nex + ad;
used[cur] = true;
}
else if (!used[nex]) {
res.push_back(0);
cur = nex;
used[cur] = true;
}
else break;
upd(cur / 2);
}
cout << "len? "<<m << " " << len << "\n";
}
int calc_obj(int n) {
int m = 1;
while (true) {
int len = m - 1 + (1 << m);
if (len < n)m++;
else break;
}
int res = 0;
for (int len = 1; len < m; len++) {
res += 1 << len;
}
for (int len = m; len <= n; len++) {
res += n - len + 1;
}
return res;
}
vector<int> mk2(int m) {
vector<int> res;
vector<bool> used(1 << m);
int cur = (1 << (m - 1)); used[cur] = true;
rep(i, m) {
if (cur & (1 << i))res.push_back(1);
else res.push_back(0);
}
int ad = 1 << (m - 1);
while (true) {
int nex = cur / 2;
if (!used[nex + ad]) {
res.push_back(1);
cur = nex + ad;
used[cur] = true;
}
else if (!used[nex]) {
res.push_back(0);
cur = nex;
used[cur] = true;
}
else break;
}
assert(res.size() == (1 << m) + m - 1);
//reverse(all(res));
return res;
}
vector<int> mk(int n) {
int m = 1;
while (true) {
int len = m - 1 + (1 << m);
if (len < n)m++;
else break;
}
if (n >= (1 << m) - 2) {
vector<int> res = mk2(m);
res.resize(n);
return res;
}
vector<int> res = mk2(m-1);
res.push_back(1);
int cur = 0;
vector<bool> used(1 << m);
int ad = 1 << (m - 1);
rep(i, res.size()) {
cur = cur / 2;
if (res[i])cur += ad;
if (i >= m - 1)used[cur] = true;
}
while (res.size() < n) {
int nex = cur / 2;
if (!used[nex + ad]) {
res.push_back(1);
cur = nex + ad;
used[cur] = true;
}
else if (!used[nex]) {
res.push_back(0);
cur = nex;
used[cur] = true;
}
else {
cout << "help!" << "\n";
}
}
return res;
}
int calc(vector<int> a) {
vector<string> vs;
rep(i, a.size()) {
string cur;
Rep(j, i, a.size()) {
cur.push_back(a[j] + '0');
vs.push_back(cur);
}
}
sort(all(vs));
vs.erase(unique(all(vs)), vs.end());
return vs.size();
}
void expr() {
for (int n = 2; n <= 100; n++) {
int obj = calc_obj(n);
vector<int> v = mk(n);
int val = calc(v);
if (obj != val) {
cout << "?? " << n << "\n";
cout << obj << " " << val << "\n";
}
}
return;
for (int m = 2; m <= 10; m++) {
expr3(m);
}
for (int m = 2; m <= 6; m++) {
//cout << "!" << "\n";
vector<int> v = mk2(m);
coutarray(v);
}
for (int n = 2; n <= 20; n++) {
int ma = 0;
vector<int> res;
rep(i, (1 << n)) {
vector<int> a(n);
rep(j, n) {
if (i & (1 << j))a[j] = 1;
else a[j] = 0;
}
int c = calc(a);
if (ma < c) {
ma = c;
swap(res, a);
}
}
vector<int> obj = mk(n);
cout << "! " << n << " " << ma <<" "<<calc(obj)<< "\n";
coutarray(res);
coutarray(obj);
}
}
void solve() {
int n; cin >> n;
vector<int> ans = mk(n);
rep(i, ans.size())cout << ans[i]; cout << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//init();
//expr();
//while(true)
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11680kb
input:
2
output:
10
result:
ok meet maximum 3
Test #2:
score: 0
Accepted
time: 9ms
memory: 11628kb
input:
5
output:
01100
result:
ok meet maximum 12
Test #3:
score: 0
Accepted
time: 4ms
memory: 11592kb
input:
1
output:
1
result:
ok meet maximum 1
Test #4:
score: 0
Accepted
time: 4ms
memory: 11596kb
input:
3
output:
011
result:
ok meet maximum 5
Test #5:
score: 0
Accepted
time: 9ms
memory: 11684kb
input:
4
output:
0110
result:
ok meet maximum 8
Test #6:
score: 0
Accepted
time: 9ms
memory: 11760kb
input:
6
output:
001110
result:
ok meet maximum 16
Test #7:
score: 0
Accepted
time: 4ms
memory: 11680kb
input:
7
output:
0011101
result:
ok meet maximum 21
Test #8:
score: 0
Accepted
time: 4ms
memory: 11680kb
input:
8
output:
00111010
result:
ok meet maximum 27
Test #9:
score: 0
Accepted
time: 3ms
memory: 11664kb
input:
9
output:
001110100
result:
ok meet maximum 34
Test #10:
score: 0
Accepted
time: 4ms
memory: 11680kb
input:
10
output:
0011101000
result:
ok meet maximum 42
Test #11:
score: 0
Accepted
time: 7ms
memory: 11688kb
input:
11
output:
00111010001
result:
ok meet maximum 50
Test #12:
score: 0
Accepted
time: 1ms
memory: 11612kb
input:
12
output:
001110100010
result:
ok meet maximum 59
Test #13:
score: -100
Time Limit Exceeded
input:
200000
output:
help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! help! ...