結果

問題 No.1159 Sashiming String
ユーザー 👑 KazunKazun
提出日時 2020-11-27 03:43:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 84,388 KB
最終ジャッジ日時 2023-10-01 03:53:16
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,332 KB
testcase_01 AC 70 ms
71,436 KB
testcase_02 AC 89 ms
76,320 KB
testcase_03 AC 82 ms
76,324 KB
testcase_04 AC 90 ms
76,488 KB
testcase_05 AC 94 ms
76,708 KB
testcase_06 AC 85 ms
76,440 KB
testcase_07 AC 89 ms
76,460 KB
testcase_08 AC 98 ms
82,304 KB
testcase_09 AC 99 ms
84,388 KB
testcase_10 AC 71 ms
71,284 KB
testcase_11 AC 70 ms
71,348 KB
testcase_12 AC 71 ms
71,240 KB
testcase_13 AC 73 ms
71,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Binary_Search_Small_Count(A,x,equal=False,sort=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()

    if A[0]>x or ((not equal) and A[0]==x):
        return 0

    L,R=0,len(A)
    while R-L>1:
        C=L+(R-L)//2
        if A[C]<x or (equal and A[C]==x):
            L=C
        else:
            R=C

    return L+1
#================================================
S=input()
N=len(S)

if "S" not in S:
    print(0)
    exit()

X=[i for i in range(N) if S[i]=="S"]

Y=[]
for i in range(N-2):
    if S[i:i+3]=="ing":
        Y.append(i)

K=0
for y in  Y:
    K+=Binary_Search_Small_Count(X,y)
print(K)
0