QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730252#4643. 方程的解数qwertim100 ✓329ms31252kbC++201.0kb2024-11-09 19:25:382024-11-09 19:25:44

Judging History

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

  • [2024-11-09 19:25:44]
  • 评测
  • 测评结果:100
  • 用时:329ms
  • 内存:31252kb
  • [2024-11-09 19:25:38]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
inline int read(){
	char c=getchar();
	int asb=0,ctx=1;
	while(c<'0'||c>'9')ctx=(c=='-'?-1:ctx),c=getchar();
	while(c>='0'&&c<='9')asb=asb*10+(c^48),c=getchar();
	return asb*ctx;
}
inline int qp(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=ans*x;
		x*=x,y>>=1;
	}
	return ans;
}
int n,m,k[10],p[10],l[4000005],r[4000005],sz[2],ans;
unordered_map<int,int>mp;
void dfs(int(&pp)[4000005],int deep,int tmp,int sum){
	if(deep>(tmp?n:(n>>1)))return pp[++sz[tmp]]=sum,void();
	fo(i,1,m)dfs(pp,deep+1,tmp,sum+k[deep]*qp(i,p[deep]));
}
signed main(){
	n=read(),m=read();
	fo(i,1,n)k[i]=read(),p[i]=read();
	dfs(l,1,0,0),dfs(r,(n>>1)+1,1,0);
	sort(l+1,l+1+sz[0]),sort(r+1,r+1+sz[1]);
	int pos1=sz[0],pos2=1;
	while(pos1&&pos2<=sz[1]){
		while(pos2<=sz[1]&&r[pos2]<-l[pos1])pos2++;
		int ppp=pos1,tmp=0,tmp2=0;
		while(pos2<=sz[1]&&r[pos2]==-l[pos1])pos2++,tmp++;
		while(pos1&&l[pos1]==l[ppp])pos1--,tmp2++;
		ans+=tmp*tmp2;
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 329ms
memory: 31252kb

input:

6
150
3 2
-3 2
3 2
-3 2
3 2
-3 2

output:

427154856

result:

ok single line: '427154856'

Test #2:

score: 10
Accepted
time: 1ms
memory: 5608kb

input:

1
50
31 4

output:

0

result:

ok single line: '0'

Test #3:

score: 10
Accepted
time: 1ms
memory: 5656kb

input:

2
150
3 2
-2 3

output:

2

result:

ok single line: '2'

Test #4:

score: 10
Accepted
time: 2ms
memory: 5764kb

input:

3
150
1 2
-1 2
1 2

output:

178

result:

ok single line: '178'

Test #5:

score: 10
Accepted
time: 219ms
memory: 20792kb

input:

5
150
1 4
1 4
1 3
-1 4
-1 4

output:

502

result:

ok single line: '502'

Test #6:

score: 10
Accepted
time: 217ms
memory: 19516kb

input:

5
150
34 3
-136 2
-98 2
38 3
-48 3

output:

1927

result:

ok single line: '1927'

Test #7:

score: 10
Accepted
time: 165ms
memory: 19320kb

input:

5
150
134 3
-311 3
254 2
-165 2
584 1

output:

567

result:

ok single line: '567'

Test #8:

score: 10
Accepted
time: 191ms
memory: 21676kb

input:

6
120
1 4
-1646265 1
-1564164 1
-1894941 1
-165442 1
-149874 1
546 3

output:

599

result:

ok single line: '599'

Test #9:

score: 10
Accepted
time: 176ms
memory: 18820kb

input:

6
120
34 2
-136 2
-98 2
38 1
-48 3
15 1

output:

147281

result:

ok single line: '147281'

Test #10:

score: 10
Accepted
time: 160ms
memory: 21900kb

input:

6
120
21 2
-2 4
-21 3
12 3
76 2
49 1

output:

84554

result:

ok single line: '84554'