QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398982 | #5434. Binary Substrings | LCX756 | RE | 2ms | 10268kb | C++14 | 2.5kb | 2024-04-25 20:38:18 | 2024-04-25 20:38:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define fir first
#define sec second
typedef vector <int> vi;
typedef vector <ll> vl;
#ifdef LCX
#define msg(args...) fprintf(stderr, args)
#else
#define msg(...) void()
#endif
const int maxn = 2e5 + 10;
int n, k;
vi vec;
int vis[maxn][2];
void dfs(int u) {
for (int c = 0; c < 2; ++c)
if (!vis[u][c]) {
vis[u][c] = 1;
int e = (u << 1 | c);
dfs(e & ((1 << (k - 1)) - 1));
vec.push_back(e);
}
}
vi circ[maxn];
void go(int u) {
vi &path = circ[u];
while (1) {
int flg = 1;
for (int c = 0; c < 2 && flg; ++c)
if (!vis[u][c]) {
vis[u][c] = 1;
u = (u << 1 | c) & ((1 << k) - 1);
path.push_back(u);
flg = 0;
}
if (flg) break;
}
}
char s[maxn];
int main() {
scanf("%d", &n);
if (n == 1) return printf("0\n"), 0;
if (n == 2) return printf("01\n"), 0;
if (n == 3) return printf("001\n"), 0;
if (n == 4) return printf("0011\n"), 0;
while ((1 << k) + k - 1 <= n) ++k;
--k;
dfs(0);
reverse(begin(vec), end(vec));
memset(vis, 0, sizeof vis);
int len = vec.size(), rst = n - (1 << k) - k + 1;
// for (int i = 0; i < len; ++i) msg("%d%c", vec[i], " \n"[i == len - 1]);
for (int i = 0; i < len; ++i)
vis[vec[i]][vec[(i + 1) % len] & 1] = 1;
vi ans;
for (int i = 0; i < len; ++i) {
go(vec[i]);
// msg("@%d\n", rst);
if (rst < (int) circ[vec[i]].size()) {
for (int j = i + 1; j < len; ++j) ans.push_back(vec[j]);
for (int j = 0; j < i; ++j) {
ans.push_back(vec[j]);
for (int u : circ[vec[j]])
ans.push_back(u);
}
ans.push_back(vec[i]);
for (int u : circ[vec[i]]) {
if (!rst) break;
--rst, ans.push_back(u);
}
break;
}
else rst -= circ[vec[i]].size();
}
// msg("ans");
// for (int u : ans) msg(" %d", u);
// msg("\n");
n = 0;
for (int i = k - 1; i > 0; --i)
s[++n] = '0' + ((ans[0] >> i) & 1);
for (int u : ans) s[++n] = '0' + (u & 1);
printf("%s\n", s + 1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9312kb
input:
2
output:
01
result:
ok meet maximum 3
Test #2:
score: 0
Accepted
time: 2ms
memory: 10052kb
input:
5
output:
01100
result:
ok meet maximum 12
Test #3:
score: 0
Accepted
time: 1ms
memory: 8520kb
input:
1
output:
0
result:
ok meet maximum 1
Test #4:
score: 0
Accepted
time: 2ms
memory: 9872kb
input:
3
output:
001
result:
ok meet maximum 5
Test #5:
score: 0
Accepted
time: 1ms
memory: 8388kb
input:
4
output:
0011
result:
ok meet maximum 8
Test #6:
score: 0
Accepted
time: 0ms
memory: 10036kb
input:
6
output:
110001
result:
ok meet maximum 16
Test #7:
score: 0
Accepted
time: 2ms
memory: 10268kb
input:
7
output:
1100010
result:
ok meet maximum 21
Test #8:
score: 0
Accepted
time: 2ms
memory: 10040kb
input:
8
output:
10001011
result:
ok meet maximum 27
Test #9:
score: -100
Runtime Error
input:
9