QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354111 | #8340. 3 Sum | xuqin | AC ✓ | 333ms | 14676kb | C++14 | 2.6kb | 2024-03-14 21:53:43 | 2024-03-18 21:48:37 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cassert>
using namespace std;
const int maxn=2e4+10, mxsz=800+10;
const int inf=2e9, M=2000153;
typedef unsigned long long ULL;
typedef long long LL;
inline int read() {
int x=0, f=1; char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
return f?x:-x;
}
char a[510][maxn];
int n, k;
int S=3;
LL mo[mxsz], val[510][mxsz];
LL v[mxsz];
inline int chk(int p1, int p2, int p3) {//chk a[p1]+a[p2]+a[p3]==10^k-1
// printf("p1=%d p2=%d p3=%d\n", p1, p2, p3);
for(int i=1; i<=S; ++i)
if((val[p1][i]+val[p2][i]+val[p3][i])%mo[i]!=v[i]) return 0;
return 1;
}
int tmp[maxn+50];
inline void init(int pos) {
int l=strlen(a[pos]+1);
for(int i=1; i<=k; ++i) tmp[i]=0;
int sz=k;
for(int i=1; i<=l; ++i)
tmp[(l-i)%k+1]+=a[pos][i]-'0';
for(int i=1; i<=k; ++i) tmp[i+1]+=tmp[i]/10, tmp[i]%=10;
while(tmp[sz+1]>0) tmp[sz+1]+=tmp[sz]/10, tmp[sz]%=10, ++sz;
while(sz>k) {
for(int i=k+1; i<=sz; ++i) tmp[(i-1)%k+1]+=tmp[i], tmp[i]=0;
for(int i=1; i<=k; ++i) tmp[i+1]+=tmp[i]/10, tmp[i]%=10;
sz=k;
while(tmp[sz+1]>0) tmp[sz+1]+=tmp[sz]/10, tmp[sz]%=10, ++sz;
}
for(int i=1; i<=k; ++i) a[pos][k-i+1]=(char)(tmp[i]+'0');
}
LL tmpv[maxn];
int main() {
srand(time(0));
int ttt=0;
for(LL i=1e9+rand()%50; ; ++i) {
int fl=1;
for(LL j=2; j*j<=i; ++j)
if(i%j==0) {fl=0; break;}
if(fl) {
mo[++ttt]=i;
if(ttt==S) break;
}
}
n=read(), k=read();
// if(n==4) return puts("3"), 0;
// if(k==859) return puts("0"), 0;
// if(k==17336) return puts("0"), 0;
for(int i=1; i<=n; ++i) {
scanf("%s", a[i]+1);
init(i);
// for(int j=1; j<=k; ++j) printf("%c", a[i][j]); puts("");
}
int ans=0;
for(int i=1; i<=n; ++i) {
for(int j=1; j<=S; ++j) {
val[i][j]=0;
for(int l=1; l<=k; ++l) val[i][j]=(val[i][j]*10+a[i][l]-'0')%mo[j];
// printf("%lld ", val[i][j]);
}
// puts("");
}
for(int j=1; j<=S; ++j) {
v[j]=0;
for(int i=1; i<=k; ++i) v[j]=(v[j]*10+9)%mo[j];
}
//10^k-1
for(int i=1; i<=n; ++i)
for(int j=i; j<=n; ++j)
for(int t=j; t<=n; ++t)
ans+=chk(i, j, t);
//2*
for(int j=1; j<=S; ++j) v[j]=(v[j]+v[j])%mo[j];
for(int i=1; i<=n; ++i)
for(int j=i; j<=n; ++j)
for(int t=j; t<=n; ++t)
ans+=chk(i, j, t);
int c0=0, c9=0;
for(int i=1; i<=n; ++i) {
int fl=1;
for(int j=1; j<=k; ++j) fl&=(a[i][j]=='0');
if(fl) ++c0;
fl=1;
for(int j=1; j<=k; ++j) fl&=(a[i][j]=='9');
if(fl) ++c9;
}
printf("%d", ans+c0*(c0+1)*(c0+2)/6+c9*(c9+1)*(c9+2)/6);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 140ms
memory: 13192kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 333ms
memory: 14104kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 173ms
memory: 14504kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
2327631
result:
ok 1 number(s): "2327631"
Test #5:
score: 0
Accepted
time: 163ms
memory: 14676kb
input:
500 2 408542968136435277974575411503179002415404345446801430469044749372949272333801248935236224652806667129749035002588943020176263162139056819871274824302889304493205266143688886696157147111754418731401856424401766968832165255416237731963027205324149660112574729610391396555581935236134531799950318...
output:
212002
result:
ok 1 number(s): "212002"
Test #6:
score: 0
Accepted
time: 276ms
memory: 14096kb
input:
500 11500 75411775796562109942642493394321873284995260953010112281856775261847503626737348402159485133662757032091519863427156582689971229143089317472838196453888261138079171290535429921921548971897026706656838415620603757605079012541561774699628665865662183868374645956694140356716037674688084770628...
output:
7675
result:
ok 1 number(s): "7675"
Test #7:
score: 0
Accepted
time: 271ms
memory: 14572kb
input:
500 11500 85355036663164764459816544518601485185320972076300982726542821424439713703229669576802138231401047471351087455159512255765325323540671792953715169122669767368905391325060775725733157611188832204902997772518104188947349204726490597030311894441123834099315122116302203972018409854605418988681...
output:
1070
result:
ok 1 number(s): "1070"
Test #8:
score: 0
Accepted
time: 2ms
memory: 5816kb
input:
1 11500 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed