QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347753 | #8340. 3 Sum | ucup-team052# | TL | 1ms | 3648kb | C++23 | 1.5kb | 2024-03-09 15:15:16 | 2024-10-13 18:48:02 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
using namespace std;
const int md[3] = {998244353, 1000000009, 1004535809};
const int N = 505;
int a[N][3],n,K;
char _s[100005];
int s[100005],t[100005];
signed main()
{
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
cin>>n>>K;
int ok[4][3]={0,0,0,0};
for(int c=0;c<3;c++)
{
for(int i=0;i<K;i++) ok[1][c]=(1LL*ok[1][c]*10+9)%md[c];
ok[2][c]=1LL*2*ok[1][c]%md[c];
ok[3][c]=1LL*3*ok[1][c]%md[c];
}
for(int i=1;i<=n;i++)
{
scanf("%s",_s+1);
int l=strlen(_s+1);
for(int j=0;j<K;j++) s[j]=0;
for(int j=0;j<l;j++) s[j]=_s[l-j]-'0';
while(l>K)
{
for(int j=0;j<K;j++) t[j]=0;
t[K]=0;
for(int j=0;j<l;j++) t[j%K]+=s[j];
for(int j=0;j<K;j++) t[j+1]+=t[j]/10,t[j]%=10;
l=t[K]?K+1:K;
for(int j=0;j<l;j++) s[j]=t[j];
}
for(int j=K-1;j>=0;j--)
{
for(int c=0;c<3;c++) a[i][c]=(1ULL*a[i][c]*10+s[j])%md[c];
}
}
// for(int i=1;i<=n;i++) printf("%d %d\n",a[i][0],a[i][1]);
// for(int i=0;i<4;i++) printf("%d %d\n",ok[i][0],ok[i][1]);
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
for(int k=j;k<=n;k++)
{
for(int t=0;t<4;t++)
{
int o=1;
for(int c=0;c<3;c++)
{
if(((long long)a[i][c]+a[j][c]+a[k][c])%md[c]!=ok[t][c]) o=0;
}
ans+=o;
}
}
}
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Time Limit Exceeded
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...