QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354107#8340. 3 SumxuqinTL 1ms3436kbC++142.6kb2024-03-14 21:51:292024-03-14 21:51:29

Judging History

你现在查看的是最新测评结果

  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-03-18 21:48:05]
  • hack成功,自动添加数据
  • (/hack/579)
  • [2024-03-18 21:45:33]
  • hack成功,自动添加数据
  • (/hack/578)
  • [2024-03-14 21:51:29]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3436kb
  • [2024-03-14 21:51:29]
  • 提交

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;
	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;
	}
	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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3436kb

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3412kb

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

500 17336
11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Time Limit Exceeded

input:

500 1
751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...

output:


result: