QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487665 | #8786. The Whole World | ucup-team4435 | TL | 1478ms | 13448kb | Python3 | 2.0kb | 2024-07-23 06:24:14 | 2024-07-23 06:24:15 |
Judging History
answer
#!/usr/bin/python3
def has_int_solution(A, b):
N = len(A)
if N == 0:
return True
M = len(A[0])
col = 0
for row in range(N):
non_zero = col
while non_zero < M and A[row][non_zero] == 0:
non_zero += 1
if non_zero == M:
if b[i] != 0:
return False
continue
if non_zero != col:
for i in range(row, N):
A[i][col], A[i][non_zero] = A[i][non_zero], A[i][col]
for j in range(col, M):
if A[row][j] < 0:
for i in range(row, N):
A[i][j] *= -1
assert A[row][col] > 0
for j in range(col + 1, M):
while A[row][j] != 0:
K = A[row][col] // A[row][j]
for i in range(row, N):
A[i][col] -= A[i][j] * K
A[i][col], A[i][j] = A[i][j], A[i][col]
if b[row] % A[row][col] != 0:
return False
K = b[row] // A[row][col]
for i in range(row + 1, N):
b[i] -= A[i][col] * K
col += 1
return True
choose = [[0 for j in range(40)] for i in range(40)]
for i in range(len(choose)):
choose[i][0] = 1
choose[i][i] = 1
for j in range(1, i):
choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1]
def solve():
n = int(input())
points = []
for i in range(n):
points.append(tuple(map(int, input().split())))
points.sort()
def check(deg):
A = [[choose[points[i][0]][j] for j in range(deg + 1)] for i in range(n)]
b = [points[i][1] for i in range(n)]
return has_int_solution(A, b)
lb = -1
rb = 31
while rb - lb > 1:
mid = (lb + rb) // 2
if check(mid):
rb = mid
else:
lb = mid
print(rb)
for _ in range(int(input())):
solve()
详细
Test #1:
score: 100
Accepted
time: 11ms
memory: 10680kb
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: 15ms
memory: 10680kb
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: 14ms
memory: 10640kb
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: 0
Accepted
time: 44ms
memory: 10864kb
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 20 20 25 23 25 26 23 23 25 29 23 24 29 29 27 25 19
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 141ms
memory: 11020kb
input:
100 10 1 158027281 3 -154375927 6 -515683907 9 -801063453 15 371607728 16 -30224647 24 -215349633 26 219182013 29 -87257968 30 186925822 10 2 205585983 9 740879281 11 -672242855 14 -53907640 16 146130715 20 -17941862 25 -424140108 26 593743162 27 -8310423 28 84863497 10 3 46810292 4 361101002 5 4687...
output:
29 25 25 20 19 25 20 29 29 19 25 19 26 26 27 21 27 26 25 25 24 26 27 25 25 27 26 23 27 23 29 25 27 26 28 29 29 20 21 23 22 25 23 16 25 29 26 25 26 18 23 18 23 19 28 19 26 26 24 18 26 19 23 27 21 23 17 26 28 25 27 23 16 19 25 26 23 25 14 23 20 20 25 23 24 23 19 19 20 20 22 26 26 25 22 23 28 17 19 19
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 84ms
memory: 10880kb
input:
100 30 1 -519015304 2 269671593 3 -163533023 4 830108438 5 337806976 6 -87888761 7 -195233355 8 -341350273 9 38092088 10 285610643 11 -240058763 12 256373103 13 297741964 14 -247379404 15 -26410774 16 -755197562 17 -643221179 18 159031836 19 689848941 20 622207228 21 -407862690 22 401550934 23 10884...
output:
29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 95ms
memory: 10760kb
input:
100 29 1 149105603 2 19193029 3 -254160491 4 -298710412 5 -329725675 6 644578442 7 611132722 8 -806708763 9 506813970 10 566271854 11 -621025393 12 293347092 13 -332652769 14 -320671582 15 507576094 16 -153368460 17 -242687628 18 545685752 19 -359086703 20 -31631637 21 34200734 22 695203819 23 66205...
output:
29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 28 29 29 29 29 28 29 29 29 29 29 29 29 28 29
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 1478ms
memory: 13448kb
input:
100 27 1 -219694090 2 313611706 3 19681553 4 -393439728 5 137039465 6 -210242538 7 -257014477 8 711593910 9 -126342644 10 317378740 12 -27880234 14 -312500245 15 -611623850 16 26965932 17 -344751802 19 25604908 20 -925684523 21 218732296 22 -906235432 23 128008760 24 128339229 25 -373435576 26 78643...
output:
29 29 29 29 29 29 29 29 29 28 28 29 29 29 28 29 29 29 29 29 29 29 29 29 29 28 28 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29 29 29 29 29 28 29 28 29 29 29 29 28 29 29 29 28 29 29 29 29 28 28 29 28 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 28 29 28 29 29 29 29 29 29 29 29 29 28 29
result:
ok 100 numbers
Test #9:
score: -100
Time Limit Exceeded
input:
100 26 1 66877446 2 -164941227 3 225463507 4 184131912 5 102090525 7 758317818 8 -97450001 9 370239141 11 3046899 13 323733227 14 -130439971 16 -635446409 17 -859978167 18 48284039 19 -447989609 20 -127277242 21 557802358 22 101519428 23 62166242 24 -314606125 25 -689141632 26 -358169960 27 -4857611...