QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274740 | #7877. Balanced Array | ucup-team2307# | WA | 12ms | 25148kb | C++20 | 2.3kb | 2023-12-03 20:54:42 | 2023-12-03 20:54:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
struct Hash
{
static constexpr int MOD=1e9+7;
long long val;
constexpr Hash(long long val=0):val(val%MOD){}
friend constexpr Hash operator*(const Hash& l,const Hash& r)
{
return {l.val * r.val%MOD};
}
friend constexpr Hash operator+(const Hash& l,const Hash& r)
{
return {(l.val+r.val)%MOD};
}
friend constexpr Hash operator-(const Hash& l,const Hash& r)
{
return {(l.val-r.val)%MOD};
}
bool constexpr operator!() const
{
return !val;
}
};
const int N=2e6+100;
constexpr Hash BASE=998244353;
Hash pw[N];
Hash a[N];
Hash h[N];
Hash get(int l,int r)
{
Hash ret=h[r]-h[l]*pw[r-l];
// cout<<"get("<<l<<","<<r<<")="<<h[r].val<<"-"<<h[l].val<<"*"<<pw[r-l].val<<"\n";
return ret;
}
int ok[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
pw[0]=1;
for(int i=1;i<N;i++)
pw[i]=pw[i-1]*BASE;
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
int x=0;
for(char c:s)
{
x*=62;
x+=(c<='9'?c-'0':c<='Z'?c-'A'+10+26:c-'a'+10);
}
a[i]=x;
}
h[0]=Hash();
for(int i=1;i<=n;i++)
h[i]=h[i-1]*BASE+a[i];
for(int k=1;k<=(n-1)/2;k++)
{
int k2=(k<<1);
int lo=k2,hi=n;
while(lo<hi)
{
int mi=(lo+hi+1)>>1;
Hash A=get(1,mi-k2);
Hash B=get(1+k,mi-k);
Hash C=get(1+k2,mi);
// cout<<"k="<<k<<" mi="<<mi<<" -> "<<1<<".."<<mi-k2<<" "<<1+k<<".."<<mi-k<<" "<<1+k2<<".."<<mi<<" -> "<<!(A-B-B+C)<<"\n";
if(!(A-B-B+C))
lo=mi;
else
hi=mi-1;
}
ok[k2+1]++;
ok[hi+1]--;
// cout<<"k="<<k<<" -> "<<k2+1<<".."<<hi<<"\n";
}
for(int i=1;i<=n;i++) {
ok[i] += ok[i - 1];
cout<<bool(ok[i]);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 24720kb
input:
3 1 2 3
output:
001
result:
ok single line: '001'
Test #2:
score: 0
Accepted
time: 12ms
memory: 23864kb
input:
9 1 2 3 2 5 4 3 8 5
output:
001010111
result:
ok single line: '001010111'
Test #3:
score: 0
Accepted
time: 8ms
memory: 23384kb
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: 4ms
memory: 25148kb
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:
0010111111101010101010101010101010111010101010101
result:
wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0010111111101010101010101010101010111010101010101'