QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#241568 | #5434. Binary Substrings | FISHER_ | WA | 2ms | 18052kb | C++14 | 1.3kb | 2023-11-06 11:50:45 | 2023-11-06 11:50:46 |
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) {
for (int i = 1; i <= k; i++) putchar('0');
for (int i = 1; i <= c; i++) putchar('0' + (rte[i] & 1));
}
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;
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13032kb
input:
2
output:
01
result:
ok meet maximum 3
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 18052kb
input:
5
output:
00011
result:
wrong answer not meet maximum 11 < 12