結果

問題 No.2274 三角彩色
ユーザー ecotteaecottea
提出日時 2023-03-02 17:18:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 79,728 KB
最終ジャッジ日時 2023-10-17 13:47:38
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,408 KB
testcase_01 AC 39 ms
53,408 KB
testcase_02 AC 39 ms
53,408 KB
testcase_03 AC 40 ms
53,408 KB
testcase_04 AC 39 ms
53,408 KB
testcase_05 AC 40 ms
53,408 KB
testcase_06 AC 39 ms
53,408 KB
testcase_07 AC 43 ms
59,052 KB
testcase_08 AC 42 ms
59,052 KB
testcase_09 AC 44 ms
59,116 KB
testcase_10 AC 42 ms
59,052 KB
testcase_11 AC 45 ms
61,252 KB
testcase_12 AC 51 ms
63,860 KB
testcase_13 AC 56 ms
65,956 KB
testcase_14 AC 57 ms
65,944 KB
testcase_15 AC 144 ms
79,708 KB
testcase_16 AC 127 ms
79,728 KB
testcase_17 AC 129 ms
79,716 KB
testcase_18 AC 167 ms
79,188 KB
testcase_19 AC 170 ms
79,236 KB
testcase_20 AC 161 ms
79,240 KB
testcase_21 AC 64 ms
68,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

# リスト a を座標圧縮したものを返す.
def coordinate_compression(a):
    n = len(a)
    x = sorted(list(set(a)))
    b = [0] * n
    for i in range(n):
        b[i] = bisect.bisect_left(x, a[i])
    return b

# 0-1 行列 a の階数を返す.
def bit_matrix_rank(a):
    n, m = len(a), len(a[0])

    i, j = 0, 0

    while i < n and j < m:
        i2 = i
        while i2 < n and not a[i2][j]:
            i2 += 1
        
        if i2 == n:
            j += 1
            continue

        a[i], a[i2] = a[i2], a[i]

        for i2 in range(n):
            if i2 == i:
                continue

            if a[i2][j]:
                for j2 in range(m):
                    a[i2][j2] ^= a[i][j2]
        
        i += 1
        j += 1
    
    return i


N, M, B, Q = map(int, input().split())

ijs = []
for _ in range(M):  
    i, j = map(int, input().split())
    ijs += [i, j]

# グラフを座標圧縮する.
ijs_cp = coordinate_compression(ijs)
h = max(ijs_cp) + 1

# mat : G の接続行列(行:頂点,列:辺)
mat = [[0 for j in range(M)] for i in range(h)]
for m in range(M):
    for t in range(2):
        mat[ijs_cp[2 * m + t]][m] = 1

# mat2 : クエリを並べた行列(行:クエリ,列:辺)
mat2 = [[0 for j in range(M)] for i in range(Q)]
for q in range(Q):
    m = list(map(int, input().split()))
    for t in range(3):
        mat2[q][m[t]] = 1

# それぞれの行列の階数を求める.
r = bit_matrix_rank(mat)
r2 = bit_matrix_rank(mat2)

resT = pow(2, r2, B)
resS = (pow(2, M - r, B) - resT + B) % B

print(resS, resT)
0