結果

問題 No.178 美しいWhitespace (1)
ユーザー nanaenanae
提出日時 2017-01-01 06:34:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-08-22 09:08:30
合計ジャッジ時間 1,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,788 KB
testcase_01 AC 16 ms
7,860 KB
testcase_02 AC 17 ms
7,860 KB
testcase_03 AC 17 ms
7,924 KB
testcase_04 AC 19 ms
8,172 KB
testcase_05 AC 19 ms
8,300 KB
testcase_06 AC 19 ms
8,312 KB
testcase_07 AC 19 ms
8,252 KB
testcase_08 AC 19 ms
8,296 KB
testcase_09 AC 19 ms
8,292 KB
testcase_10 AC 19 ms
8,268 KB
testcase_11 AC 19 ms
8,368 KB
testcase_12 AC 19 ms
8,220 KB
testcase_13 AC 18 ms
8,368 KB
testcase_14 AC 19 ms
8,172 KB
testcase_15 AC 19 ms
8,292 KB
testcase_16 AC 19 ms
8,180 KB
testcase_17 AC 18 ms
8,352 KB
testcase_18 AC 19 ms
8,172 KB
testcase_19 AC 19 ms
8,372 KB
testcase_20 AC 18 ms
8,400 KB
testcase_21 AC 19 ms
8,256 KB
testcase_22 AC 18 ms
7,860 KB
testcase_23 AC 18 ms
8,248 KB
testcase_24 AC 18 ms
7,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# yukicoder No.178 美しいWhitespace (1)

def is_complete(space_n, tab_n): # 完璧にできるときは必要な全角スペースの数を、そうでないときは-1を返す関数
    parity = [i % 2 for i in space_n] # スペースの数の偶奇リスト
    zspace_num = 0
    
    if parity.count(1) == len(parity) or parity.count(0) == len(parity): # 全ての行のスペースの数の偶奇が一致しているときだけ完全に出来る
        width = [a + 4 * b for (a,b) in zip(space_n, tab_n)]
        max_w = max(width)
        
        for (a,b) in zip(space_n, tab_n):
            zspace_num += (max_w - (a + 4 * b)) // 2 # 必要な全角スペースの数をカウント
        
        return zspace_num
    else: # 偶奇が一致していないときは不可
        return -1

# 入力部
N = int(input())
space_n = []
tab_n = []

for _ in range(N):
    a, b = map(int, input().split())
    space_n.append(a)
    tab_n.append(b)

# 出力部
print(is_complete(space_n, tab_n))
0