QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499297 | #8340. 3 Sum | xqbf | RE | 1ms | 5908kb | C++14 | 1.8kb | 2024-07-31 11:33:40 | 2024-07-31 11:33:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=505,maxk=20005;
int n,k,a[maxn][maxk],p[15]={998244353,1000000007,1019344367,1000000009,19260817},len[maxn],p1[maxk],p2[maxk],p3[maxk];
string s;
int b[maxn][15],prime=5;
int resm[15],resm2[15];
signed main(){
//freopen("M.in","r",stdin);
//freopen("M.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>s;
for(int j=0;j<s.size();j++){
a[i][s.size()-j-1]=s[j]-'0';
}
len[i]=s.size();
while(len[i]>k){
for(int j=0;j<k;j++){
p1[j]=a[i][j];
}
for(int j=k;j<len[i];j++){
p2[j-k]=a[i][j];
}
int len1=k,len2=len[i]-k,carry=0;
for(int j=len1;j<len[i];j++)p1[j]=0;
for(int j=len2;j<len[i];j++)p2[j]=0;
for(int j=0;j<max(len1,len2);j++){
int tmp=(p1[j]+p2[j]+carry)%10;
carry=(p1[j]+p2[j]+carry)/10;
a[i][j]=tmp;
}
len[i]=max(len1,len2);
if(carry!=0)a[i][len[i]++]=carry;
}
}
//for(int i=1;i<=n;i++)printf("%lld\n",a[i][0]);
for(int v=0;v<prime;v++){
resm[v]=0;resm2[v]=0;
for(int i=0;i<k;i++){
resm[v]=(resm[v]*10+9)%p[v];
}
resm2[v]=(resm[v]+resm[v])%p[v];
for(int i=1;i<=n;i++){
for(int j=len[i]-1;j>=0;j--){
b[i][v]=(b[i][v]*10+a[i][j])%p[v];
}
}
}
assert(n<=400);
int ans=0;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
for(int k=j;k<=n;k++){
int flag0=1,flag1=1,flag2=1;
for(int v=0;v<5;v++){
int tmp=(b[i][v]+b[j][v]+b[k][v])%p[v];
if(tmp!=0){
flag0=0;
}
if(tmp!=resm[v]){
flag1=0;
}
if(tmp!=resm2[v]){
flag2=0;
}
if((flag0==0)&&(flag1==0)&&(flag2==0)){
break;
}
}
if((flag0==0)&&(flag1==0)&&(flag2==0));
else{ans++;}
}
}
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5908kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Runtime Error
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...