QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#437563#8786. The Whole Worlducup-team1004WA 99ms9596kbPython31.2kb2024-06-09 13:30:122024-06-09 13:30:13

Judging History

This is the latest submission verdict.

  • [2024-06-09 13:30:13]
  • Judged
  • Verdict: WA
  • Time: 99ms
  • Memory: 9596kb
  • [2024-06-09 13:30:12]
  • Submitted

answer

T=int(input())
def gcd(n,m):
	if m==0:
		return n
	else:
		return gcd(m,n%m)
def binom(n,m):
	if 0>m or m>n:
		return 0
	else:
		ans=1
		for i in range(m):
			ans=ans*(n-i)//(i+1)
		return ans
while T>0:
	n=int(input())
	x=[0 for i in range(n)]
	y=[0 for i in range(n)]
	for i in range(n):
		x[i],y[i]=map(int,input().split(' '))
	def chk(x,y,k):
		# print("chk",x,y,k)
		a=[[0 for i in range(k+2)] for j in range(n)]
		for i in range(n):
			a[i][k+1]=y[i]
			for j in range(k+1):
				a[i][j]=binom(x[i],j)
		for i in range(min(n,k+1)):
			for j in range(i+1,n):
				while a[j][i]:
					w=a[i][i]//a[j][i]
					for p in range(k+2):
						a[i][p]-=a[j][p]*w
					a[j],a[i]=a[i],a[j]
		vis=[0 for i in range(k+1)]
		ans=[0 for i in range(k+1)]
		for i in range(n-1,-1,-1):
			g=0
			t=0
			cur=-1
			for j in range(k+1):
				if vis[j]:
					a[i][k+1]-=ans[j]*a[i][j]
					a[i][j]=0
				if a[i][j]:
					cur=j
					t+=1
				g=gcd(g,a[i][j])
			if g==0:
				if a[i][k+1]!=0:
					return 0
			else:
				if a[i][k+1]%g!=0:
					return 0
				if t==1:
					vis[cur]=1
					ans[cur]=a[i][k+1]/g
		# print(a)
		return 1
	ans=0
	while not chk(x,y,ans):
		ans+=1
	print(ans)
	T-=1

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 9456kb

input:

2
2
1 0
4 1
3
1 1
4 4
6 6

output:

3
1

result:

ok 2 number(s): "3 1"

Test #2:

score: 0
Accepted
time: 4ms
memory: 9576kb

input:

2
2
1 0
4 1
3
1 0
3 0
5 4

output:

3
3

result:

ok 2 number(s): "3 3"

Test #3:

score: 0
Accepted
time: 8ms
memory: 9596kb

input:

2
10
1 557
2 -172
3 -497
5 763
6 -149
7 -355
8 -29
9 -588
10 -171
11 -355
10
1 -461
2 -219
3 -45
4 -212
5 749
6 -294
9 -85
10 213
11 -412
12 125

output:

10
11

result:

ok 2 number(s): "10 11"

Test #4:

score: -100
Wrong Answer
time: 99ms
memory: 9508kb

input:

20
10
1 -193165761
4 426322868
5 -408198139
7 -455731045
9 -389028341
17 -590246653
18 119481348
21 809814532
23 47591392
26 -21020402
10
3 -715116939
5 -263142266
6 -426687860
10 342227448
14 141724722
15 576758779
18 123410194
19 256532828
20 -223524833
25 386574889
10
5 34943085
7 238431559
9 168...

output:

25
22
23
19
19
25
23
23
26
23
23
25
29
23
23
29
29
27
25
19

result:

wrong answer 4th numbers differ - expected: '20', found: '19'