QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241571 | #5434. Binary Substrings | FISHER_ | WA | 5ms | 21028kb | C++14 | 1.3kb | 2023-11-06 11:52:27 | 2023-11-06 11:52:28 |
Judging History
answer
#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
using namespace std;
const int maxn = 400000;
vector<int> g[maxn + 5];
int rte[maxn + 5];
int c;
bool vis[2 * maxn + 5];
int S;
void dfs(int u) {
if (vis[u]) return;
vis[u] = 1;
dfs((u << 1) & (S - 1)), dfs(((u << 1) & (S - 1)) | 1);
rte[++c] = u;
}
int to[2 * maxn + 5];
int main() {
int n;
scanf("%d", &n);
if (n == 1) return puts("0"), 0;
if (n == 2) return puts("01"), 0;
int k = 1;
while ((1 << k) + k - 1 <= n) k++;
S = 1 << (k - 1);
dfs(0);
reverse(rte + 1, rte + c + 1);
for (int i = 1; i <= c; i++) rte[i] = (rte[i] << 1) | (rte[i + 1] & 1);
if (n == S + k - 2) {
for (int i = 1; i < k - 1; i++) putchar('0');
for (int i = 1; i <= c; i++) putchar('0' + (rte[i] & 1));
return 0;
}
memset(to, -1, sizeof(to));
for (int i = 1; i <= c; i++) to[rte[i]] = rte[i % c + 1];
int S2 = 1 << k;
for (int i = 0; i < S2; i++)
if (to[i] == -1) to[i] = to[i ^ S] ^ 1;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < S2; i++)
if (!vis[i]) {
for (int u = i; !vis[u]; u = to[u]) vis[u] = 1, c++;
swap(to[i], to[i ^ S]);
if (c + k > n) {
for (int j = k - 1; ~j; j--) putchar('0' + ((i >> j) & 1));
for (int j = k + 1, u = to[i]; j <= n; j++, u = to[u]) putchar('0' + (u & 1));
return 0;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13100kb
input:
2
output:
01
result:
ok meet maximum 3
Test #2:
score: 0
Accepted
time: 3ms
memory: 13548kb
input:
5
output:
01100
result:
ok meet maximum 12
Test #3:
score: 0
Accepted
time: 0ms
memory: 14332kb
input:
1
output:
0
result:
ok meet maximum 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 17884kb
input:
3
output:
001
result:
ok meet maximum 5
Test #5:
score: 0
Accepted
time: 5ms
memory: 18624kb
input:
4
output:
0010
result:
ok meet maximum 8
Test #6:
score: 0
Accepted
time: 0ms
memory: 18668kb
input:
6
output:
000110
result:
ok meet maximum 16
Test #7:
score: 0
Accepted
time: 0ms
memory: 18332kb
input:
7
output:
0001100
result:
ok meet maximum 21
Test #8:
score: 0
Accepted
time: 0ms
memory: 18076kb
input:
8
output:
00101100
result:
ok meet maximum 27
Test #9:
score: 0
Accepted
time: 0ms
memory: 17992kb
input:
9
output:
001011000
result:
ok meet maximum 34
Test #10:
score: 0
Accepted
time: 0ms
memory: 13548kb
input:
10
output:
0010111000
result:
ok meet maximum 42
Test #11:
score: 0
Accepted
time: 4ms
memory: 17204kb
input:
11
output:
00001011100
result:
ok meet maximum 50
Test #12:
score: 0
Accepted
time: 2ms
memory: 17052kb
input:
12
output:
000010111000
result:
ok meet maximum 59
Test #13:
score: -100
Wrong Answer
time: 0ms
memory: 21028kb
input:
200000
output:
000000000000000001111111111111111011111111000000000111111101111111110000000011111111011111110000000000111111011111111110000000111111111011111100000000000111110111111111110000001111111111011111000000000000111101111111111110000011111111111011110000000000000111011111111111110000111111111111011100000000...
result:
wrong answer not meet maximum 17649501338 < 19996962278