QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#272349 | #7877. Balanced Array | ucup-team1321# | WA | 1ms | 9624kb | C++20 | 1.7kb | 2023-12-02 16:58:48 | 2023-12-02 16:58:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int a[N];
int digit(char a) {
if ('0' <= a && a <= '9') return a - '0';
if ('a' <= a && a <= 'z') return a - 'a' + 10;
return a - 'A' + 36;
}
int read() {
string s;
cin >> s;
int x = 0;
for (char a : s)
x = x * 62 + digit(a);
return x;
}
const unsigned long long BASE=1e9+7;
unsigned long long v[N];
unsigned long long pw[N];
unsigned long long get_hash(int l,int r)
{
return v[r]-v[l-1]*pw[r-l+1];
}
int c[N];
bool isprime[N];
void init(int n)
{
fill(isprime+1,isprime+n+1,true);
isprime[1]=false;
for(int i=2;i<=n;i++)
if(isprime[i])
for(int j=i+i;j<=n;j+=i)
isprime[j]=false;
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++) a[i] = read();
pw[0]=1;
for(int i=1;i<=n;i++)
pw[i]=pw[i-1]*BASE;
for(int i=1;i<=n;i++)
v[i]=v[i-1]*BASE+a[i];
init(n/2);
for(int k=1;k<=n/2;k++)
if(k==1||isprime[k])
{
int l=k*2+1,r=n,p=0;
auto check=[=](int x)
{
return get_hash(1,x-2*k)+get_hash(2*k+1,x)==get_hash(k+1,x-k)*2;
};
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid)) p=mid,l=mid+1;
else r=mid-1;
}
int ql=k*2+1,qr=p;
if(ql<=qr) c[ql]++,c[qr+1]--;
}
for(int i=1;i<=n;i++)
c[i]+=c[i-1];
for(int i=1;i<=n;i++)
if(c[i]) cout<<"1";
else cout<<"0";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9544kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 1ms
memory: 9624kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 1ms
memory: 9528kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9612kb
input:
49 71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke
output:
0000111111000000000000000000000000110000000000000
result:
wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0000111111000000000000000000000000110000000000000'