QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#432790#8786. The Whole Worlducup-team004#TL 636ms11988kbPython31.0kb2024-06-07 17:35:092024-06-07 17:35:09

Judging History

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

  • [2024-06-07 17:35:09]
  • 评测
  • 测评结果:TL
  • 用时:636ms
  • 内存:11988kb
  • [2024-06-07 17:35:09]
  • 提交

answer

def add(n, a, x):
    for i in range(n):
        while x[i] != 0:
            t = a[i][i] // x[i]
            for j in range(i, n):
                a[i][j] -= x[j] * t
            a[i], x = x, a[i]
            
def check(n, a, x):
    for i in range(n):
        if x[i] != 0:
            if a[i][i] == 0 or x[i] % a[i][i] != 0:
                return False
            t = x[i] // a[i][i]
            for j in range(i, n):
                x[j] -= a[i][j] * t
    return True

def solve():
    n = int(input())
    a = [[0] * n for i in range(n)]
    x = [0] * n
    y = [0] * n
    cd = []
    for i in range(n):
        cd.append(tuple(map(int, input().split())))
    cd.sort()
    for i in range(n):
        x[i], y[i] = cd[i]
    ans = 0
    v = [1] * n
    add(n, a, list(v))
    
    while not check(n, a, list(y)):
        ans += 1
        for i in range(n):
            v[i] = v[i] * (x[i] - ans + 1) // ans
        add(n, a, list(v))
    print(ans)

T = int(input())
for case in range(T):
    solve()

详细

Test #1:

score: 100
Accepted
time: 10ms
memory: 9444kb

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

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: 9ms
memory: 9448kb

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: 16ms
memory: 9612kb

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: 56ms
memory: 9648kb

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: 100ms
memory: 9568kb

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

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: 636ms
memory: 11988kb

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...

output:

29
29
28
29
29
29
28
29
29
29
29
29
29
28
29
29
28
28
29
29
29
29
29
29
28
29
28
27
29
27
28
29
29
29
29
29
28
29
29
28
29
28
29
29
29
29
28
28
29
29
29
29
29
29
29
29
29
29
28
29
28
29
28
27
29
29
28
29
29
29
29

result: