Submission #15801318


Source Code Expand

Copy
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:], ), cache=True)
def main(S):
S = S.copy()
l_ind = np.where(S == -1)[0][:-1] + 1
r_ind = np.where(S == -1)[0][1:]
#
N = len(l_ind)
for i in range(N):
S[l_ind[i]:r_ind[i]] = S[l_ind[i]:r_ind[i]][::-1]
# Trie
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(S):
    S = S.copy()
    l_ind = np.where(S == -1)[0][:-1] + 1
    r_ind = np.where(S == -1)[0][1:]

    # 逆順にしておく
    N = len(l_ind)
    for i in range(N):
        S[l_ind[i]:r_ind[i]] = S[l_ind[i]:r_ind[i]][::-1]

    # Trie木の構築
    path = np.zeros_like(S)
    child = np.zeros((len(S), 26), np.int64)
    is_end = np.zeros(len(S), np.bool_)

    n_node = 1
    for i in range(N):
        node = 0
        for j in range(l_ind[i], r_ind[i]):
            path[j] = node
            if child[node][S[j]] == 0:
                child[node][S[j]] = n_node
                n_node += 1
            node = child[node][S[j]]
        is_end[node] = True
    child = child[:n_node]
    is_end = is_end[:n_node]
    ans = 0
    for i in range(N):
        se = 0
        for j in range(r_ind[i] - 1, l_ind[i] - 1, -1):
            se |= 1 << S[j]
            node = path[j]
            for k in range(26):
                if se & 1 << k:
                    if is_end[child[node][k]]:
                        ans += 1
    return ans - N

N = int(readline())
S = np.array(list(read().rstrip()), np.int64)

S[S == ord('\n')] = -1
S[S > 0] -= ord('a')
S = np.insert(S, 0, -1)
S = np.append(S, -1)

print(main(S))

Submission Info

Submission Time
Task B - First Second
User maspy
Language Python (3.8.2)
Score 700
Code Size 1504 Byte
Status AC
Exec Time 815 ms
Memory 381348 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt
All 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
001.txt AC 488 ms 106552 KB
002.txt AC 483 ms 107088 KB
003.txt AC 484 ms 107084 KB
004.txt AC 491 ms 120268 KB
005.txt AC 656 ms 279812 KB
006.txt AC 727 ms 342084 KB
007.txt AC 757 ms 361756 KB
008.txt AC 800 ms 381348 KB
009.txt AC 740 ms 355236 KB
010.txt AC 762 ms 345328 KB
011.txt AC 723 ms 340740 KB
012.txt AC 697 ms 342024 KB
013.txt AC 706 ms 341724 KB
014.txt AC 710 ms 340832 KB
015.txt AC 726 ms 342088 KB
016.txt AC 715 ms 342520 KB
017.txt AC 696 ms 342204 KB
018.txt AC 713 ms 341756 KB
019.txt AC 719 ms 342700 KB
020.txt AC 815 ms 374044 KB
021.txt AC 773 ms 350064 KB
022.txt AC 751 ms 343112 KB
023.txt AC 743 ms 340420 KB
024.txt AC 733 ms 341844 KB
s1.txt AC 469 ms 106360 KB
s2.txt AC 465 ms 107096 KB


2025-04-11 (Fri)
22:23:10 +00:00