QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281798 | #3033. Harry Potter and the Palindromic Radius | Dualqwq | 100 ✓ | 626ms | 17192kb | C++20 | 1.7kb | 2023-12-10 20:11:18 | 2023-12-10 20:11:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
#define iL (1 << 20)
char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
template<typename T>
inline void read(T &a)
{
char ch;int sign = 0;
for(ch = gc();!isdigit(ch);ch = gc())
if(ch == '-') sign = 1;
a = ch & 15;
for(ch = gc();isdigit(ch);ch = gc())
a = (a << 3) + (a << 1) + (ch & 15);
if(sign) a = -a;
}
char Out[iL],*iter = Out;
#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
template<typename T>
inline void write(T x,char end = '\n')
{
int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
do c[++l] = x % 10,x /= 10; while(x);
while(l) *iter++ = c[l--] + '0';
flush();
}
#undef iL
#undef gc
#undef flush
}
using namespace FastIO;
const int N = 1e6 + 5,M = 2.5e7 + 5;
int n,R[N];
int a[N];
int rp[N];
inline void Main() {
read(n);
for(int i = 1;i <= n;i++) read(R[i]);
a[1] = a[2] = 0;
for(int i = 2;i < n;i++)
if(R[i] > 0) a[i + 1] = a[i - 1]; else a[i + 1] = a[i - 1] ^ 1;
a[0] = 3;a[n + 1] = 4;
int l = 0,r = 0;
for(int i = 1;i <= n;i++) {
if(r >= i) rp[i] = min(r - i + 1,rp[2 * l - i]);
else rp[i] = 0;
while(a[i - rp[i]] == a[i + rp[i]]) ++rp[i];
if(i + rp[i] - 1 > r) r = i + rp[i] - 1,l = i;
}
for(int i = 1;i <= n;i++)
if(rp[i] != R[i] + 1) return puts("0"),void();
puts("4");
for(int a = 0;a < 2;++a)
for(int b = 0;b < 2;++b) {
for(int i = 1;i <= n;i++) {
int x = ::a[i] ^ ((i & 1) ? a : b);
putchar(x + 48);
}
putchar('\n');
}
}
int main() {
int T;
read(T);
while(T--) Main();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 626ms
memory: 17192kb
input:
131112 2 0 0 2 0 1 2 0 0 2 1 0 2 0 0 2 0 1 2 0 0 2 0 1 3 0 1 0 3 0 1 1 3 0 0 0 3 0 1 0 3 0 1 0 3 0 2 0 3 0 0 0 3 1 0 0 3 0 0 0 3 1 0 0 3 0 1 0 3 0 2 0 3 0 0 0 3 0 0 1 3 0 1 0 3 0 2 0 4 0 1 1 0 4 0 1 2 0 4 0 0 1 0 4 0 0 1 1 4 0 1 0 0 4 0 1 0 1 4 0 0 0 0 4 0 0 1 0 4 0 0 1 0 4 1 0 1 0 4 0 1 1 0 4 0 1 2...
output:
4 00 01 10 11 0 4 00 01 10 11 0 4 00 01 10 11 0 4 00 01 10 11 0 4 000 010 101 111 0 4 001 011 100 110 4 000 010 101 111 4 000 010 101 111 0 4 001 011 100 110 0 4 001 011 100 110 0 4 000 010 101 111 0 4 001 011 100 110 0 4 000 010 101 111 0 4 0000 0101 1010 1111 0 4 0010 0111 1000 1101 0 4 0001 0100 ...
result:
ok 401208 lines