結果

問題 No.1225 I hate I hate Matrix Construction
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-11 21:48:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 76,604 KB
最終ジャッジ日時 2023-08-27 13:52:12
合計ジャッジ時間 4,594 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,240 KB
testcase_01 AC 67 ms
71,160 KB
testcase_02 AC 69 ms
71,240 KB
testcase_03 AC 74 ms
75,560 KB
testcase_04 AC 83 ms
76,488 KB
testcase_05 AC 77 ms
76,088 KB
testcase_06 AC 79 ms
76,408 KB
testcase_07 AC 74 ms
75,752 KB
testcase_08 AC 77 ms
75,944 KB
testcase_09 AC 80 ms
76,192 KB
testcase_10 AC 79 ms
76,376 KB
testcase_11 AC 81 ms
76,512 KB
testcase_12 AC 85 ms
76,424 KB
testcase_13 AC 77 ms
75,980 KB
testcase_14 AC 72 ms
75,680 KB
testcase_15 AC 78 ms
76,396 KB
testcase_16 AC 79 ms
76,540 KB
testcase_17 AC 81 ms
76,568 KB
testcase_18 AC 86 ms
76,564 KB
testcase_19 AC 79 ms
76,196 KB
testcase_20 AC 81 ms
76,348 KB
testcase_21 AC 85 ms
76,500 KB
testcase_22 AC 86 ms
76,156 KB
testcase_23 AC 87 ms
76,340 KB
testcase_24 AC 80 ms
76,300 KB
testcase_25 AC 81 ms
76,412 KB
testcase_26 AC 81 ms
76,340 KB
testcase_27 AC 69 ms
71,516 KB
testcase_28 AC 84 ms
76,472 KB
testcase_29 AC 79 ms
76,536 KB
testcase_30 AC 85 ms
76,392 KB
testcase_31 AC 86 ms
76,392 KB
testcase_32 AC 89 ms
76,296 KB
testcase_33 AC 81 ms
76,604 KB
testcase_34 AC 91 ms
76,472 KB
testcase_35 AC 91 ms
76,188 KB
testcase_36 AC 84 ms
76,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

ds = [set() for i in range(3)]
dt = [set() for i in range(3)]

for i, s in enumerate(S):
    ds[s].add(i)
for i, t in enumerate(T):
    dt[t].add(i)

A = [[0]*n for _ in range(n)]
for i in ds[2]:
    for j in range(n):
        A[i][j] = 1

for j in dt[2]:
    for i in range(n):
        A[i][j] = 1

for i in ds[1]:
    cnt = 0
    for j in range(n):
        if A[i][j] == 1:
            cnt += 1
    if cnt == 0:
        for j in range(n):
            if j not in dt[0] and j in dt[1]:
                A[i][j] = 1
                dt[1].remove(j)
                break
        else:
            for j in range(n):
                if j not in ds[0]:
                    if A[i][j] == 0:
                        A[i][j] = 1
                        break
    #ds[1].remove(i)

for j in dt[1]:
    cnt = 0
    for i in range(n):
        if A[i][j] == 1:
            cnt += 1
    if cnt == 0:
        for i in range(n):
            #if i not in ds[0] and i in ds[1]:
            if i not in ds[0] and A[i][j] == 0:
                A[i][j] = 1
                #ds[1].remove(i)
                break
        else:
            for i in range(n):
                if i not in ds[0]:
                    if A[i][j] == 0:
                        A[i][j] = 1
                        break
    #dt[1].remove(j)
#print(A)
ans = 0
for i in range(n):
    for j in range(n):
        ans += A[i][j]
print(ans)
0