QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347816 | #8340. 3 Sum | ucup-team346# | WA | 7ms | 34128kb | C++14 | 1.6kb | 2024-03-09 15:37:54 | 2024-03-09 15:37:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
int n,K;
#define M 505
#define N 100005
char A[M][N];
const ll P = 1e17+19;
ll B[M];
int cnt = 0;
int tmp[M];
signed main(){
cin>>n>>K;
for(int i=1;i<=n;i++){
scanf("%s",A[i]+1);
int len = strlen(A[i] + 1);
reverse(A[i]+1,A[i]+1+len);
for(int j=1;j<=K+1;j++)tmp[j]=0;
for(int j=1;j<=len;j+=K){
for(int k=1;k<=K;k++){
int v = tmp[k] + (j+k-1 > len ? 0 : (int)(A[i][j+k-1]-'0'));
tmp[k] = v%10;
tmp[k+1] += v/10;
}
while(tmp[K+1]){
assert(tmp[K+1] == 1);
tmp[K+1] = 0;
int k=1;
for(;k<=K && tmp[k]==9;k++)
tmp[k] = 0;
tmp[k]++;
}
int flg = 1;
for(int k=1;k<=K && flg;k++)
if(tmp[k]!=9)flg = 0;
if(flg){
for(int k=1;k<=K;k++)tmp[k]=0;
}
}
int flg = 1;
for(int j=1;flg && j<=K;j++)
if(tmp[j] != 0)flg = 0;
cnt += flg;
for(int j=K;j>=1;j--)
B[i] = (10*B[i]+tmp[j])%P;
}
int a=0,b=0;
for(int i=1;i<=K;i++)
a=(10ll*a+9)%P;
b=2*a%P;
unordered_map<ll,int> pos;
ll ans = 1ll*(cnt+2)*(cnt+1)*cnt/6;
for(int i=n;i>=1;i--){
pos[B[i]]++;
for(int j=i;j>=1;j--){
ans += pos[(P+P+a-B[i]-B[j])%P];
ans += pos[(P+P+b-B[i]-B[j])%P];
}
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 34128kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'