結果

問題 No.572 妖精の演奏
ユーザー ckawatakckawatak
提出日時 2019-03-09 17:20:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 77,612 KB
最終ジャッジ日時 2023-09-05 19:51:08
合計ジャッジ時間 3,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 104 ms
71,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
M = int(input())

S = []
for i in range(M):
    scores = list(map(int, input().split(' ')))
    que = deque()
    for score_index in sorted([(score,i) for i,score in enumerate(scores)]):
        que.append(score_index)
    S.append(que)

U = []
for i in range(M):
    U.append(deque())

def total(start, number):
    visited = [False for _ in range(M)]
    total = 0
    n = 0
    i = start
    
    while n < number:
        score,next = S[i].pop()
        if visited[next]:
            U[i].append((score,next))            
            continue
        visited[next] = True
        U[i].append((score,next))
        total = total + score
        i = next
        n = n + 1
        
    for j in range(M):
        for _ in range(len(U[j])):
            S[j].append(U[j].pop())
            
    return total,i

if N < M:
    print(0)
    exit(0)

division = N // M
residual = N % M

answer = 0
for i in range(M):
    total1,start = total(i,M)
    total2,last = total(start,residual-1)
    answer = max(answer, total1 * division + total2)

print(answer)
0