QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499242 | #8340. 3 Sum | xqbf | TL | 350ms | 82476kb | C++14 | 1.7kb | 2024-07-31 10:20:22 | 2024-07-31 10:20:22 |
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(){
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];
}
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5884kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 80ms
memory: 81776kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 350ms
memory: 82476kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Time Limit Exceeded
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...