QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487541#8786. The Whole Worlducup-team4435#TL 16ms10888kbPython34.0kb2024-07-22 23:14:562024-07-22 23:14:56

Judging History

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

  • [2024-07-22 23:14:56]
  • 评测
  • 测评结果:TL
  • 用时:16ms
  • 内存:10888kb
  • [2024-07-22 23:14:56]
  • 提交

answer

def check(A):
    n = len(A)
    m = len(A[0]) - 1
    s = 0

    def SwapRows(i, j):
        if i != j:
            A[i], A[j] = A[j], A[i]

    def SwapCols(i, j):
        if i != j:
            for t in range(n):
                A[t][i], A[t][j] = A[t][j], A[t][i]

    # A[:,j] += A[:,i] * c
    def AddCol(i, j, c):
        if c != 0:
            for t in range(n):
                A[t][j] += A[t][i] * c

    # A[j] += A[i] * c
    def AddRow(i, j, c):
        if c != 0:
            for t in range(m + 1):
                A[j][t] += A[i][t] * c

    def MulRow(i, c):
        for t in range(m + 1):
            A[i][t] *= c

    def MulCol(i, c):
        for t in range(n):
            A[t][i] *= c

    while s < n and s < m:
        if A[s][s] == 0:
            for i in range(s, n):
                for j in range(s, m):
                    if A[i][j] != 0:
                        SwapRows(i, s)
                        SwapCols(j, s)
                        assert A[s][s] != 0
                        break
                if A[s][s] != 0:
                    break
        if A[s][s] == 0:
            break
        while True:
            ok = True
            if A[s][s] < 0:
                MulRow(s, -1)
            assert A[s][s] > 0

            for j in range(s + 1, m):
                if A[s][j] % A[s][s] != 0:
                    value = A[s][j] // A[s][s]
                    if value * A[s][s] > A[s][j]:
                        value -= 1
                    AddCol(s, j, -value)
                    ok = False
                    SwapCols(j, s)
                    break

            if not ok:
                continue

            for j in range(s + 1, n):
                if A[j][s] % A[s][s] != 0:
                    value = A[j][s] // A[s][s]
                    if value * A[s][s] > A[j][s]:
                        value -= 1
                    AddRow(s, j, -value)
                    ok = False
                    SwapRows(j, s)
                    break

            if not ok:
                continue

            for i in range(s + 1, n):
                for j in range(s + 1, m):
                    if A[i][j] % A[s][s] == 0:
                        continue
                    AddRow(i, s, 1)
                    ok = False
                    break
                if not ok:
                    break

            if not ok:
                continue

            for j in range(s + 1, m):
                value = A[s][j] // A[s][s]
                if value * A[s][s] > A[s][j]:
                    value -= 1
                AddCol(s, j, -value)
                assert A[s][j] == 0

            for j in range(s + 1, n):
                value = A[j][s] // A[s][s]
                if value * A[s][s] > A[j][s]:
                    value -= 1
                AddRow(s, j, -value)
                assert A[j][s] == 0

            break
        if A[s][m] % A[s][s] != 0:
            return False
        s += 1
    for i in range(s, n):
        if A[i][m] != 0:
            return False
    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())
    x = [0] * n
    y = [0] * n
    for i in range(n):
        x[i], y[i] = map(int, input().split())

    def check2(m):
        a = [[0 for j in range(m + 2)] for i in range(n)]
        for i in range(n):
            a[i][-1] = y[i]
            for j in range(m + 1):
                a[i][j] = choose[x[i]][j]
        return check(a)

    rb = 32
    # while not check2(rb):
    #     rb *= 2

    lb = -1
    while rb - lb > 1:
        mid = (lb + rb) // 2
        if check2(mid):
            rb = mid
        else:
            lb = mid

    print(rb)


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

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 10800kb

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

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

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

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

result: