QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499705 | #8340. 3 Sum | xqbf | WA | 398ms | 83188kb | C++14 | 2.4kb | 2024-07-31 17:17:46 | 2024-07-31 17:17:51 |
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],resm3[15];
vector<int> rest[maxk];
map<int,vector<int> > mp;
inline int am(int a,int b,int mod){
return a+b>=mod?a+b-mod:a+b;
}
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();
int up=(len[i]-1)/k;
for(int j=0;j<=up;j++)rest[j].clear();
for(int j=0;j<len[i];j++){
rest[j/k].push_back(a[i][j]);
}
for(int j=0;j<k;j++)p1[j]=rest[0][j];
int len1=k,len2=0;
for(int o=1;o<=up;o++){
//printf("%d!\n",rest[o].size());
for(int v=0;v<rest[o].size();v++){
p2[v]=rest[o][v];
}
len2=rest[o].size();
int len3=max(len1,len2),carry=0;
for(int j=len1;j<len3;j++)p1[j]=0;
for(int j=len2;j<len3;j++)p2[j]=0;
for(int j=0;j<len3;j++){
int tmp=(p1[j]+p2[j]+carry)%10;
carry=(p1[j]+p2[j]+carry)/10;
p1[j]=tmp;
}
len1=len3;
if(carry!=0)p1[len1++]=carry;
}
len[i]=len1;
for(int j=0;j<len1;j++)a[i][j]=p1[j];
}
/*for(int i=1;i<=n;i++){
for(int j=0;j<len[i];j++)
printf("%lld",a[i][0]);
puts("");
}*/
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];
resm3[v]=(resm[v]+resm2[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,flag3=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(tmp!=resm3[v]){
flag3=0;
}
if((flag0==0)&&(flag1==0)&&(flag2==0)&&(flag3==0)){
break;
}
}
if((flag0==0)&&(flag1==0)&&(flag2==0)&&(flag3==0));
else{//printf("%lld %lld %lld\n",i,j,k);
ans++;}
}
}
}
printf("%lld\n",ans);
return 0;
}
/*
4 1
0
1
10
17
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4320kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 78ms
memory: 82296kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 398ms
memory: 83040kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 211ms
memory: 83188kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
0
result:
wrong answer 1st numbers differ - expected: '2327631', found: '0'