結果

問題 No.1512 作文
ユーザー kohei2019kohei2019
提出日時 2021-05-21 21:57:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,622 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 124,012 KB
最終ジャッジ日時 2024-04-18 15:20:19
合計ジャッジ時間 6,903 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,736 KB
testcase_01 AC 38 ms
52,992 KB
testcase_02 AC 38 ms
52,352 KB
testcase_03 AC 39 ms
52,992 KB
testcase_04 AC 381 ms
99,072 KB
testcase_05 AC 374 ms
99,012 KB
testcase_06 AC 364 ms
96,256 KB
testcase_07 AC 375 ms
99,064 KB
testcase_08 AC 376 ms
99,104 KB
testcase_09 AC 62 ms
76,544 KB
testcase_10 AC 65 ms
75,776 KB
testcase_11 AC 64 ms
76,032 KB
testcase_12 AC 66 ms
76,364 KB
testcase_13 AC 62 ms
76,248 KB
testcase_14 AC 125 ms
77,568 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 127 ms
77,824 KB
testcase_20 WA -
testcase_21 AC 46 ms
61,184 KB
testcase_22 AC 45 ms
59,264 KB
testcase_23 AC 47 ms
61,824 KB
testcase_24 AC 48 ms
61,952 KB
testcase_25 AC 47 ms
61,568 KB
testcase_26 AC 39 ms
52,864 KB
testcase_27 AC 40 ms
52,864 KB
testcase_28 AC 40 ms
52,352 KB
testcase_29 AC 38 ms
52,864 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 59 ms
81,664 KB
testcase_36 AC 61 ms
81,664 KB
testcase_37 AC 55 ms
73,088 KB
testcase_38 AC 62 ms
77,056 KB
testcase_39 AC 66 ms
76,928 KB
testcase_40 AC 473 ms
112,688 KB
testcase_41 AC 316 ms
124,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
sys.setrecursionlimit(10**7)

class segki():
    DEFAULT = {
        'min': 1 << 60,
        'max': -(1 << 60),
        'sum': 0,
        'prd': 1,
        'gcd': 0,
        'lmc': 1,
        '^': 0,
        '&': (1 << 60) - 1,
        '|': 0,
    }

    FUNC = {
        'min': min,
        'max': max,
        'sum': (lambda x, y: x + y),
        'prd': (lambda x, y: x * y),
        'gcd': math.gcd,
        'lmc': (lambda x, y: (x * y) // math.gcd(x, y)),
        '^': (lambda x, y: x ^ y),
        '&': (lambda x, y: x & y),
        '|': (lambda x, y: x | y),
    }

    def __init__(self, N, ls, mode='min'):
        """
        葉の数N, 要素ls, 関数mode (min,max,sum,prd(product),gcd,lmc,^,&,|)
        """
        self.default = self.DEFAULT[mode]
        self.func = self.FUNC[mode]
        self.N = N
        self.K = (N - 1).bit_length()
        self.N2 = 1 << self.K
        self.dat = [self.default] * (2**(self.K + 1))
        for i in range(self.N):  # 葉の構築
            self.dat[self.N2 + i] = ls[i]
        self.build()

    def build(self):
        for j in range(self.N2 - 1, -1, -1):
            self.dat[j] = self.func(self.dat[j << 1], self.dat[j << 1 | 1])  # 親が持つ条件

    def leafvalue(self, x):  # リストのx番目の値
        return self.dat[x + self.N2]

    def update(self, x, y):  # index(x)をyに変更
        i = x + self.N2
        self.dat[i] = y
        while i > 0:  # 親の値を変更
            i >>= 1
            self.dat[i] = self.func(self.dat[i << 1], self.dat[i << 1 | 1])
        return

    def query(self, L, R):  # [L,R)の区間取得
        L += self.N2
        R += self.N2
        vL = self.default
        vR = self.default
        while L < R:
            if L & 1:
                vL = self.func(vL, self.dat[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.dat[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)

def iimoji(snum):
    for k in range(len(snum)-1):
        if snum[k] > snum[k+1]:
            return False
    return True
N = int(input())
alpha = list('abcdefghijklmnopqrstuvwxyz')
Sall = [input() for i in range(N)]
sall = []
for i in range(N):
    S = Sall[i]
    Snum = []
    for j in range(len(S)):
        Snum.append(alpha.index(S[j]))
    if iimoji(Snum):
        sall.append(Snum)
sall.sort(key=lambda x:x[-1])
sall.sort(key=lambda x:x[0])
SG = segki(27,[0]*27,mode='max')
for i in range(len(sall)):
    S = sall[i]
    v = SG.query(0,S[0]+1)
    SG.update(S[-1],v+len(S))
print(SG.query(0,26))
0