# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22716 | 현우야 이거 플로우야 (#40) | Unifying Values (KRIII5_UV) | C++11 | 9 ms | 1312 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
typedef long long lli;
const lli mod=1e9+7;
int n;
lli sum[10001];
int chk[10001];
lli cnt[10001];
lli pow(lli a, lli p) {
lli res=1;
while(p) {
if(p&1) res=(res*a)%mod;
a=(a*a)%mod;
p>>=1;
}
return res;
}
int main() {
lli zsum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",sum+i);
sum[i]+=sum[i-1];
if(sum[i]==0) ++zsum;
}
--zsum;
lli res=0;
for(int i=1;i<n;i++) {
if(sum[i]==0) {
--zsum;
if(sum[n]!=0) continue;
res=(res+pow(2,zsum))%mod;
}
else {
if((sum[n]>0&&sum[i]>0||sum[n]<0&&sum[i]<0)&&sum[n]%sum[i]!=0)
continue;
lli k=sum[n]/sum[i];
if(k==1||k>n) continue;
cnt[1]=1; chk[1]=i;
for(int j=i+1;j<=n;j++) {
if((sum[j]>0&&sum[i]>0||sum[j]<0&&sum[i]<0)&&sum[j]%sum[i]==0) {
lli k=sum[j]/sum[i];
if(k>n||k==1) continue;
if(chk[k-1]!=i) continue;
if(chk[k]!=i) {
chk[k]=i;
cnt[k]=0;
}
cnt[k]=(cnt[k]+cnt[k-1])%mod;
}
}
if(chk[k-1]!=i) continue;
res=(res+cnt[k])%mod;
}
}
printf("%lld\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |