Submission #51593193


Source Code Expand

import bisect

n = int(input())

s = input().strip()
t = input().strip()

a = {}
for i in range(len(s)):
    if s[i] not in a:
        a[s[i]] = []
    a[s[i]].append(i)

def check(k):
    global n
    if k == 0:
        return True
    x, y = 0, 0
    for i in range(len(t)):
        if t[i] not in a:
            return False
        j = bisect.bisect_left(a[t[i]], y)
        # print(i, t[i], j, a[t[i]], x, y)
        if len(a[t[i]]) - j > k:
            y = a[t[i]][j + k-1]+1
        else:
            tmp = k - (len(a[t[i]]) - j)
            x += 1
            y = 0
            x += tmp // len(a[t[i]])
            tmp %= len(a[t[i]])
            if tmp == 0:
                x -= 1
                y = a[t[i]][-1]+1
            else:
                y = a[t[i]][tmp - 1]+1
        if x > n:
            return False
    return x < n

l, r = 0, len(s)*n//len(t)+1
while l != r:
    mid = (l + r + 1)//2
    if check(mid):
        l = mid
    else:
        r = mid - 1

print(l)

Submission Info

Submission Time
Task F - SSttrriinngg in StringString
User yefllower
Language Python (PyPy 3.10-v7.3.12)
Score 525
Code Size 1037 Byte
Status AC
Exec Time 1660 ms
Memory 89148 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 50
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_zero_00.txt, 03_zero_01.txt, 03_zero_02.txt, 03_zero_03.txt, 03_zero_04.txt, 03_zero_05.txt, 04_border_00.txt, 04_border_01.txt, 04_border_02.txt, 04_border_03.txt, 05_handmade_00.txt, 05_handmade_01.txt, 05_handmade_02.txt, 05_handmade_03.txt, 05_handmade_04.txt, 05_handmade_05.txt, 05_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 63 ms 76664 KiB
00_sample_01.txt AC 61 ms 76404 KiB
00_sample_02.txt AC 62 ms 76196 KiB
01_random_00.txt AC 1660 ms 89028 KiB
01_random_01.txt AC 1622 ms 88212 KiB
01_random_02.txt AC 1535 ms 85280 KiB
01_random_03.txt AC 1539 ms 85204 KiB
01_random_04.txt AC 1379 ms 84620 KiB
01_random_05.txt AC 253 ms 89148 KiB
01_random_06.txt AC 268 ms 88296 KiB
01_random_07.txt AC 263 ms 85356 KiB
01_random_08.txt AC 257 ms 84652 KiB
01_random_09.txt AC 239 ms 84320 KiB
01_random_10.txt AC 104 ms 89064 KiB
01_random_11.txt AC 113 ms 87964 KiB
01_random_12.txt AC 115 ms 85432 KiB
01_random_13.txt AC 115 ms 84076 KiB
01_random_14.txt AC 113 ms 83980 KiB
01_random_15.txt AC 92 ms 88932 KiB
01_random_16.txt AC 89 ms 87928 KiB
01_random_17.txt AC 89 ms 84844 KiB
01_random_18.txt AC 89 ms 83500 KiB
01_random_19.txt AC 90 ms 83472 KiB
01_random_20.txt AC 76 ms 87520 KiB
01_random_21.txt AC 77 ms 86596 KiB
01_random_22.txt AC 76 ms 84912 KiB
01_random_23.txt AC 78 ms 83240 KiB
01_random_24.txt AC 78 ms 83120 KiB
02_random2_00.txt AC 1498 ms 85780 KiB
02_random2_01.txt AC 702 ms 83520 KiB
02_random2_02.txt AC 130 ms 83564 KiB
02_random2_03.txt AC 1122 ms 85220 KiB
02_random2_04.txt AC 485 ms 84724 KiB
03_zero_00.txt AC 93 ms 85572 KiB
03_zero_01.txt AC 83 ms 82928 KiB
03_zero_02.txt AC 101 ms 84188 KiB
03_zero_03.txt AC 94 ms 83788 KiB
03_zero_04.txt AC 79 ms 83460 KiB
03_zero_05.txt AC 61 ms 76300 KiB
04_border_00.txt AC 89 ms 82928 KiB
04_border_01.txt AC 76 ms 81812 KiB
04_border_02.txt AC 70 ms 83372 KiB
04_border_03.txt AC 80 ms 82912 KiB
05_handmade_00.txt AC 69 ms 87524 KiB
05_handmade_01.txt AC 1399 ms 88892 KiB
05_handmade_02.txt AC 59 ms 76668 KiB
05_handmade_03.txt AC 68 ms 87444 KiB
05_handmade_04.txt AC 58 ms 76612 KiB
05_handmade_05.txt AC 59 ms 76648 KiB
05_handmade_06.txt AC 58 ms 76460 KiB