結果
問題 | No.1650 Moving Coins |
ユーザー | Kiri8128 |
提出日時 | 2021-08-20 21:53:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 1,898 bytes |
コンパイル時間 | 398 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 176,728 KB |
最終ジャッジ日時 | 2024-10-14 03:26:46 |
合計ジャッジ時間 | 8,964 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,352 KB |
testcase_01 | AC | 40 ms
52,352 KB |
testcase_02 | AC | 42 ms
52,480 KB |
testcase_03 | AC | 60 ms
66,304 KB |
testcase_04 | AC | 50 ms
59,008 KB |
testcase_05 | AC | 57 ms
64,384 KB |
testcase_06 | AC | 56 ms
65,408 KB |
testcase_07 | AC | 61 ms
68,480 KB |
testcase_08 | AC | 217 ms
129,716 KB |
testcase_09 | AC | 207 ms
130,612 KB |
testcase_10 | AC | 223 ms
130,288 KB |
testcase_11 | AC | 230 ms
131,164 KB |
testcase_12 | AC | 184 ms
116,788 KB |
testcase_13 | AC | 186 ms
117,360 KB |
testcase_14 | AC | 226 ms
128,740 KB |
testcase_15 | AC | 169 ms
109,312 KB |
testcase_16 | AC | 249 ms
135,484 KB |
testcase_17 | AC | 243 ms
134,464 KB |
testcase_18 | AC | 262 ms
146,088 KB |
testcase_19 | AC | 293 ms
174,160 KB |
testcase_20 | AC | 298 ms
175,452 KB |
testcase_21 | AC | 323 ms
176,728 KB |
testcase_22 | AC | 253 ms
147,808 KB |
testcase_23 | AC | 263 ms
147,560 KB |
testcase_24 | AC | 48 ms
57,088 KB |
testcase_25 | AC | 48 ms
57,984 KB |
testcase_26 | AC | 212 ms
132,704 KB |
ソースコード
def scc(E): n = len(E) iE = [[] for _ in range(n)] for i, e in enumerate(E): for v in e: iE[v].append(i) T = [] done = [0] * n # 0 -> 1 -> 2 ct = 0 for i0 in range(n): if done[i0]: continue Q = [~i0, i0] while Q: i = Q.pop() if i < 0: if done[~i] == 2: continue done[~i] = 2 T.append(~i) ct += 1 continue if i >= 0: if done[i]: continue done[i] = 1 for j in E[i]: if done[j]: continue Q.append(~j) Q.append(j) done = [0] * n SCC = [] ### ID が必要なとき I = [0] * n ### for i0 in T[::-1]: if done[i0]: continue L = [] Q = [~i0, i0] while Q: i = Q.pop() if i < 0: if done[~i] == 2: continue done[~i] = 2 L.append(~i) ### I[~i] = len(SCC) ### continue if i >= 0: if done[i]: continue done[i] = 1 for j in iE[i]: if done[j]: continue Q.append(~j) Q.append(j) SCC.append(L) return SCC, I N = int(input()) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] ans = sum([abs(a - b) for a, b in zip(A, B)]) X = [[] for _ in range(N)] for i in range(N - 1): if B[i] >= A[i+1]: X[i+1].append(i) if B[i+1] <= A[i]: X[i].append(i + 1) L, I = scc(X) print(ans) ANS = [] for a in L: i = a[0] if B[i] > A[i]: ANS += [str(i + 1) + " R"] * (B[i] - A[i]) elif B[i] < A[i]: ANS += [str(i + 1) + " L"] * (A[i] - B[i]) print("\n".join(ANS))