QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771722 | #7877. Balanced Array | einekleine18 | RE | 17ms | 50748kb | C++20 | 2.8kb | 2024-11-22 15:16:10 | 2024-11-22 15:16:15 |
Judging History
answer
#include<bits/stdc++.h>
#include <cctype>
#include <vector>
#define int long long
constexpr int mod1=2147483647;
constexpr int mod2=2147483629;
constexpr int N=3e6+5;
struct Hash{
int a,b;
Hash operator+(const Hash&p) const {
return {(a+p.a)%mod1,(b+p.b)%mod2};
}
Hash operator-(const Hash&p) const {
return {(a-p.a+mod1)%mod1,(b-p.b+mod2)%mod2};
}
Hash operator*(const Hash&p) const {
return {(a*p.a)%mod1,(b*p.b)%mod2};
}
bool operator==(const Hash&p) const {
return a==p.a&&b==p.b;
}
bool operator<(const Hash&p) const {
if(a!=p.a) return a<p.a;
return b<p.b;
}
}p[N];
Hash base{131,13331};
void slove(){
p[0]={1,1};
for(int i=1;i<N;++i){
p[i]=p[i-1]*base;
}
auto get=[&](int l,int r,std::vector<Hash>&f)->Hash {
return f[r]-f[l-1]*p[r-l+1];
};
auto hash=[&](std::vector<int>& s)->std::vector<Hash> {
int sz=s.size();
std::vector<Hash>f(sz+1);
for(int i=1;i<=sz;++i){
f[i]=f[i-1]*base+Hash({s[i-1],s[i-1]});
}
return f;
};
int n;
std::cin>>n;
std::vector<int>a(n);
for(int i=0;i<n;++i){
std::string s;
std::cin>>s;
int val=0;
for(auto &x:s){
if(std::isupper(x)){
val=val*62+x-'A'+36;
}else if(std::islower(x)){
val=val*62+x-'a'+10;
}else{
val=val*62+x-'0';
}
}
a[i]=val;
}
std::vector<Hash> f=hash(a);
std::vector<int>sum(n+1);
auto ok=[&](int mid,int i)->bool {
int l1=1,r1=mid-2*i;
int l2=2*i+1,r2=mid;
int l3=i+1,r3=mid-i;
int flag=0;
if(l1<=r1&&l2<=r2&&l3<=r3){
if(get(l1,r1,f)+get(l2,r2,f)==get(l3,r3,f)+get(l3,r3,f)){
flag=1;
}
}
return flag;
};
// for(int i=0;i<n;++i){
// std::cout<<a[i]<<' ';
// }
// std::cout<<'\n';
for(int i=1;i<=n/2;++i){
int l=2*i+1,r=n;
sum[l]+=1;
while(l<r){
int mid=l+r+1>>1;
if(ok(mid,i)) l=mid;
else r=mid-1;
}
// std::cout<<i<<' '<<l<<' '<<r<<'\n';
if(ok(l,i)){
sum[l+1]-=1;
}else{
sum[l]-=1;
}
}
for(int i=1;i<=n;++i){
sum[i]+=sum[i-1];
if(sum[i]){
std::cout<<1;
}else{
std::cout<<0;
}
}
}
signed main(){
#ifdef LOCAL
std::freopen("in.txt","r",stdin);
std::freopen("out.txt","w",stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _=1;
// std::cin>>_;
for(int i=0;i<_;++i){
slove();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 50684kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 14ms
memory: 50460kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 10ms
memory: 50656kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010111
result:
ok single line: '001010111'
Test #4:
score: 0
Accepted
time: 16ms
memory: 50420kb
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:
0000111111001000000000001000000000110000100000001
result:
ok single line: '0000111111001000000000001000000000110000100000001'
Test #5:
score: 0
Accepted
time: 10ms
memory: 50424kb
input:
48 4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2
output:
001100000000001100000000000011100000000000001110
result:
ok single line: '001100000000001100000000000011100000000000001110'
Test #6:
score: 0
Accepted
time: 12ms
memory: 50428kb
input:
50 6NIbv 6ZUpG 7c6DR 7oiS2 6NIbv 6NIbv 8Uivo 6NIbv 6NIqD 6NIbv 6NHWa 6NHVS 6NIrs 6NIrB 6NIqy 84jAs 6NIFL 6BvXk 6NHW0 6NIqV 6NIqZ 6NIr3 6NHGf 6NHVY 6NIrC 6NHVT 6NIqp 6NIbv 6NIFB 6NHW8 4TPq0 6NHVq 6NJa1 6NIbv 6NIbv 6NHVG 6NHGv 6Bwsa 6pke7 6NIbv 6NIGt 6Bwsq 6piID 6d6ZU 6NIrk 6NIr4 6NHVR 5c7Qh 6NIrv 6NHVQ
output:
00110000000000001100001000001000100011101111000000
result:
ok single line: '00110000000000001100001000001000100011101111000000'
Test #7:
score: 0
Accepted
time: 16ms
memory: 50420kb
input:
47 6vtDV 6vtTo 6vu8v 6vtE6 6vuD5 6vtDE 6vtEj 6vtDz 6vvCf 6vtnU 4Mrgd 5NjpO 6vtEH 6vu99 6vtDd 6vxl6 6vtDw 6vu8V 5RBQQ 8XwN1 6vtTo 5K2nw 7UTxg 6vu8U 6vu94 6vu9o 6vtTo 6vu8W 6vu9u 6vtTo 6vB2h 6vtnE 6vu9l 5dK3A 6vtE8 6vtDA 5dK3L bpzGE 6vtEh 4YB6W 9kirr 6vuEa 6vuDP 6vtTo 6vu99 6vu8H 6vtTo
output:
00001000110010110000000000000011110011111110000
result:
ok single line: '00001000110010110000000000000011110011111110000'
Test #8:
score: 0
Accepted
time: 17ms
memory: 50720kb
input:
43 4HIA8 4HI4x 4HI4a 4HI4a 4HIzV 4HIzQ 63TJC 4HIk5 4HIzI 4HIAc 4HIzy 4HIA5 7q4T6 4HIk5 4HI42 4HIk5 4HIzi 4HJ5R 4HJ4W 4HJ60 4HIk5 4HI52 6jqi6 4HIA2 a8rc4 4HIzD 4HI3U 6UCuG 4HIk5 66aXe 4HIA4 4HIk5 4HIk5 4HIk5 4HIA6 4HIA2 4HJzK 4HI4R 4HJBS 4HIk5 4HIzj 6lBPF 4HHzW
output:
0000000010101010111100001110000000001010001
result:
ok single line: '0000000010101010111100001110000000001010001'
Test #9:
score: 0
Accepted
time: 12ms
memory: 50748kb
input:
877 5dUft 5dTKA 5dUfb 5dU0n 5dTLe 5dU0n 5dUfZ 5dUfW 5dU0n 5dU0n 5dU0n 5dUg0 5dU0n 5dUgp 5dUgp 5dUga 5dTLz 5dU0n 5dUKM 5dU0n 5dUgP 5dUgS 5dUvX 5dTwL 5dU0n 5dTKA 5dU0n 5dTKI 5dTKY 5dU0n 5dU0n 5dUg8 5dThF 5dUga 5dVgn 5dU0n 5dUfN 5dTKL 5dU0n 5dU0n 5dTKv 5dTKt 5dU0n 5dU0n 5dUeZ 5dTKI 5dU0n 5dUfq 5dU0n 7U...
output:
000000000000001111111111100000001111000000000000000010000000110000111110000000000000000000000010001110000000000000000000000000000000000000000000111111100000001000000000000000000011000000000011001000000000001100111110000000000011110000000000111111111111111100111111111000000000000000000000000011000000...
result:
ok single line: '000000000000001111111111100000...1111111100001111110000111111111'
Test #10:
score: 0
Accepted
time: 8ms
memory: 50460kb
input:
969 8ZtYL 8ZtJI 8ZueD 8ZtYL 8ZtJh 5MmwD 8ZtYL 8ZueS 8ZueR 8ZtID 8ZtIZ 8ZtYL 8ZueT 8ZtYL 8ZtIH 8ZtII 8ZuuX 8ZtHy 8Ztdl 8ZtIW 8ie68 8ZueK 8ZueN 8ZtYL 8ZtYL 8Zuet 6WmHa 8ZtJR 8ZueN 7hWYh 8ZtYL 8ZueL 8ZtJ0 8Zues 8ZtYL 4MAd1 8ZtYL 8ZtIW 8ZueM 8ZtYL 8ZtJA 8ZueE 8ZueQ 8ZtIF 8ZtYL 8ZtYL 8ZtYL 8ZtYL 8ZtIN 8Z...
output:
000000100000000011100000000000000000000000000010000000111011111100000000000000000000000010000000001111111110000000111100111000000011000000111111111111000000000000000000000000100011100000111111111000000011000010000000000000000000000000000011110000101100000011111111111110000000111111110000001000000000...
result:
ok single line: '000000100000000011100000000000...1111111110100000001111001111111'
Test #11:
score: 0
Accepted
time: 4ms
memory: 50520kb
input:
957 52EFb 52Epl 52Epl 52EEh 52E9e 52E9w 52EDn 52DT7 52Epl 52EEY 52E9f 52E9H 52EF6 52E9f 52Epl 52Ea3 52E9v 52EUB 52E9l 8ahpl 52DDj 52DU3 52EUR 52DEd 52EFs 52EaA 52EFc 52EaC 8ZnAe 52EFq 52Epl 52EFl 52EEO 7X1Ra 52Epl 52Epl 8pSGU 52EEK 52EFo 52Ea0 52CBr 52DoL 52Fqn 52CE9 52Ea5 52Eau 52EFh 52E9V 52EFq 52...
output:
000000110000000011001111110000000000000011110000000000000011111111110000000000000000000011111000001100111100000000111000000000000000111111111111001111111111111111100011001000000010100000000000000010111111111111111111110000111011111110000000111100000000111111111000000000110000000000000000000000100000...
result:
ok single line: '000000110000000011001111110000...0000000000111111111100001100000'
Test #12:
score: -100
Runtime Error
input:
990 74n7K 74n6R 74nCP 74n6Z 74o7U 74n77 74oCZ 74n7f 74p84 7f5lh 74nmP 74nmP 74n6U 74nmP 74nCW 74n6W 74r8o 7pNzH 74n74 4LqKL 74nBU 74nCN 74mAZ 74nCF 74n7Y 74n6L 74tDN 7Le29 74l64 2hMaf 74nQZ 74nSL 74m54 74nSv 4XPoO 74nmP 74nmP 74nCE 8FhCh 59GcQ 74nBJ 74nB5 7km2a 74n6J 74n7S 74nmP 74o7A 74n95 74mAH 74...