QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771645 | #7877. Balanced Array | einekleine18 | WA | 14ms | 50716kb | C++20 | 2.6kb | 2024-11-22 14:52:05 | 2024-11-22 14:52:11 |
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*63+x-'0';
}
}
a[i]=val;
}
std::vector<Hash> f=hash(a);
std::vector<int>sum(n+1);
for(int i=1;i<=n;++i){
int l=2*i+1,r=n;
sum[l]+=1;
while(l<r){
int mid=l+r+1>>1;
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;
}
}
if(flag) l=mid;
else r=mid-1;
}
sum[l+1]-=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: 14ms
memory: 50420kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 13ms
memory: 50716kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: -100
Wrong Answer
time: 7ms
memory: 50420kb
input:
9 1C 3f 4S 3h 88 6x 4W d1 8c
output:
001010101
result:
wrong answer 1st lines differ - expected: '001010111', found: '001010101'