QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487669#8786. The Whole Worlducup-team4435TL 1400ms12420kbPython31.9kb2024-07-23 06:28:292024-07-23 06:28:30

Judging History

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

  • [2024-07-23 06:28:30]
  • 评测
  • 测评结果:TL
  • 用时:1400ms
  • 内存:12420kb
  • [2024-07-23 06:28:29]
  • 提交

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 = M
        for j in range(col, M):
            if A[row][j] != 0 and (non_zero == M or A[row][non_zero] > A[row][j]):
                non_zero = j
        
        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(100)] for i in range(100)]
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)

    ans = 0
    while not check(ans):
        ans += 1
        assert ans < len(choose)
    
    print(ans)

for _ in range(int(input())):
    solve()

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 10772kb

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: 10860kb

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: 10ms
memory: 10892kb

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: 322ms
memory: 12208kb

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: 1400ms
memory: 12420kb

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: 300ms
memory: 11064kb

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: 328ms
memory: 11048kb

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: -100
Time Limit Exceeded

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

result: