Submission #69531539


Source Code Expand

from itertools import permutations
from bisect import bisect_left
from collections import defaultdict

infty = 10 ** 9
def lis(a):
    n = len(a)
    dp = [infty] * (n + 1)
    dp[0] = -infty
    for ai in a:
        i = bisect_left(dp, ai)
        dp[i] = ai
    return bisect_left(dp, infty) - 1

n = int(input())
p = tuple(map(lambda s_: int(s_) - 1, input().split()))
c = tuple(map(lambda s_: int(s_), input().split()))
ans = 0
bu = [[] for _ in range(n + 1)]
for i in range(n):
    bu[c[i]].append(p[i])

ans = 0
for ci, bi in enumerate(bu):
    l = lis(bi)
    ansi = (len(bi) - l) * ci
    ans += ansi
print(ans)



Submission Info

Submission Time
Task B - Slime Swap
User wasd314
Language Python (PyPy 3.10-v7.3.12)
Score 500
Code Size 654 Byte
Status AC
Exec Time 200 ms
Memory 154520 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 32
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 69 ms 76856 KiB
00_sample_01.txt AC 67 ms 77040 KiB
01_random_00.txt AC 142 ms 119920 KiB
01_random_01.txt AC 121 ms 101048 KiB
01_random_02.txt AC 122 ms 101652 KiB
01_random_03.txt AC 116 ms 96224 KiB
01_random_04.txt AC 103 ms 90516 KiB
01_random_05.txt AC 196 ms 154208 KiB
01_random_06.txt AC 187 ms 154028 KiB
01_random_07.txt AC 196 ms 154264 KiB
01_random_08.txt AC 200 ms 154084 KiB
01_random_09.txt AC 200 ms 154104 KiB
01_random_10.txt AC 147 ms 131632 KiB
01_random_11.txt AC 105 ms 93708 KiB
01_random_12.txt AC 176 ms 148660 KiB
01_random_13.txt AC 111 ms 95372 KiB
01_random_14.txt AC 175 ms 147732 KiB
01_random_15.txt AC 185 ms 154088 KiB
01_random_16.txt AC 183 ms 154372 KiB
01_random_17.txt AC 182 ms 154156 KiB
01_random_18.txt AC 181 ms 154008 KiB
01_random_19.txt AC 190 ms 154316 KiB
01_random_20.txt AC 174 ms 148504 KiB
01_random_21.txt AC 96 ms 88896 KiB
01_random_22.txt AC 101 ms 97152 KiB
01_random_23.txt AC 150 ms 132176 KiB
01_random_24.txt AC 181 ms 154404 KiB
01_random_25.txt AC 181 ms 154088 KiB
01_random_26.txt AC 184 ms 153820 KiB
01_random_27.txt AC 169 ms 154092 KiB
01_random_28.txt AC 181 ms 154520 KiB
01_random_29.txt AC 182 ms 154156 KiB