Submission #6254802
Source Code Expand
Copy
N, Q = map(int, input().split())s = '#' + input() + '#'T = []D = []for t, d in [input().split() for _ in range(Q)]:T.append(t)D.append(-1 if d=='L' else 1)#そのゴーレムがどちらかの端にたどりつけるかの関数def canReachEnd(iL, dir):nowL = iLnowt = s[iL]for t, d in zip(T, D):if t == nowt:nowL += dnowt = s[nowL]if dir == 1 and nowL == N+1:return Trueelif dir == -1 and nowL == 0:return Trueelse:
N, Q = map(int, input().split()) s = '#' + input() + '#' T = [] D = [] for t, d in [input().split() for _ in range(Q)]: T.append(t) D.append(-1 if d=='L' else 1) #そのゴーレムがどちらかの端にたどりつけるかの関数 def canReachEnd(iL, dir): nowL = iL nowt = s[iL] for t, d in zip(T, D): if t == nowt: nowL += d nowt = s[nowL] if dir == 1 and nowL == N+1: return True elif dir == -1 and nowL == 0: return True else: return False #1. iは左にたどり着くがi+1は辿りつかないようなiを探す left = 0 right = N+1 while right > left+1: check = (left+right)//2 if canReachEnd(check, -1): left = check else: right = check leftborder = left #2. jは右にたどり着くがj-1は辿りつかないようなjを探す left = leftborder right = N+1 while right > left+1: check = (left+right)//2 if canReachEnd(check, 1): right = check else: left = check rightborder = right dropcnt = 0 dropcnt += leftborder dropcnt += (N-(rightborder-1)) print(N-dropcnt)
Submission Info
Submission Time | |
---|---|
Task | C - Snuke the Wizard |
User | TeruMiyake |
Language | Python (3.4.3) |
Score | 500 |
Code Size | 1108 Byte |
Status | AC |
Exec Time | 1167 ms |
Memory | 42600 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 17 ms | 3064 KB |
sample_02.txt | AC | 17 ms | 3064 KB |
sample_03.txt | AC | 17 ms | 3064 KB |
test_01.txt | AC | 1136 ms | 42584 KB |
test_02.txt | AC | 1138 ms | 42584 KB |
test_03.txt | AC | 861 ms | 42584 KB |
test_04.txt | AC | 806 ms | 42528 KB |
test_05.txt | AC | 769 ms | 42568 KB |
test_06.txt | AC | 1111 ms | 42584 KB |
test_07.txt | AC | 1049 ms | 42500 KB |
test_08.txt | AC | 1073 ms | 42508 KB |
test_09.txt | AC | 797 ms | 42500 KB |
test_10.txt | AC | 727 ms | 42484 KB |
test_11.txt | AC | 911 ms | 42500 KB |
test_12.txt | AC | 771 ms | 42568 KB |
test_13.txt | AC | 785 ms | 42600 KB |
test_14.txt | AC | 790 ms | 42512 KB |
test_15.txt | AC | 820 ms | 42528 KB |
test_16.txt | AC | 808 ms | 42512 KB |
test_17.txt | AC | 1167 ms | 42584 KB |
test_18.txt | AC | 846 ms | 33404 KB |
test_19.txt | AC | 973 ms | 42584 KB |
test_20.txt | AC | 788 ms | 37384 KB |
test_21.txt | AC | 924 ms | 42584 KB |
test_22.txt | AC | 761 ms | 37188 KB |
test_23.txt | AC | 750 ms | 42584 KB |
test_24.txt | AC | 734 ms | 40196 KB |
test_25.txt | AC | 626 ms | 36228 KB |
test_26.txt | AC | 362 ms | 21260 KB |