結果
問題 | No.1859 ><<< |
ユーザー | mkawa2 |
提出日時 | 2024-11-11 00:06:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 2,351 bytes |
コンパイル時間 | 457 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 183,292 KB |
最終ジャッジ日時 | 2024-11-11 00:07:10 |
合計ジャッジ時間 | 12,075 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,144 KB |
testcase_01 | AC | 45 ms
54,528 KB |
testcase_02 | AC | 48 ms
54,400 KB |
testcase_03 | AC | 50 ms
54,272 KB |
testcase_04 | AC | 249 ms
183,232 KB |
testcase_05 | AC | 243 ms
183,108 KB |
testcase_06 | AC | 237 ms
183,232 KB |
testcase_07 | AC | 242 ms
183,100 KB |
testcase_08 | AC | 232 ms
183,232 KB |
testcase_09 | AC | 234 ms
183,228 KB |
testcase_10 | AC | 99 ms
90,368 KB |
testcase_11 | AC | 115 ms
103,424 KB |
testcase_12 | AC | 148 ms
128,316 KB |
testcase_13 | AC | 120 ms
106,496 KB |
testcase_14 | AC | 176 ms
130,276 KB |
testcase_15 | AC | 203 ms
154,480 KB |
testcase_16 | AC | 229 ms
172,612 KB |
testcase_17 | AC | 198 ms
126,268 KB |
testcase_18 | AC | 229 ms
163,076 KB |
testcase_19 | AC | 184 ms
125,984 KB |
testcase_20 | AC | 211 ms
154,688 KB |
testcase_21 | AC | 227 ms
176,204 KB |
testcase_22 | AC | 235 ms
174,148 KB |
testcase_23 | AC | 195 ms
153,904 KB |
testcase_24 | AC | 223 ms
175,964 KB |
testcase_25 | AC | 235 ms
171,864 KB |
testcase_26 | AC | 213 ms
158,896 KB |
testcase_27 | AC | 141 ms
114,612 KB |
testcase_28 | AC | 250 ms
162,880 KB |
testcase_29 | AC | 221 ms
158,704 KB |
testcase_30 | AC | 216 ms
154,536 KB |
testcase_31 | AC | 213 ms
154,228 KB |
testcase_32 | AC | 237 ms
179,728 KB |
testcase_33 | AC | 208 ms
154,356 KB |
testcase_34 | AC | 245 ms
163,248 KB |
testcase_35 | AC | 227 ms
179,908 KB |
testcase_36 | AC | 225 ms
179,844 KB |
testcase_37 | AC | 211 ms
154,824 KB |
testcase_38 | AC | 240 ms
183,292 KB |
testcase_39 | AC | 262 ms
179,928 KB |
testcase_40 | AC | 217 ms
174,832 KB |
testcase_41 | AC | 221 ms
179,708 KB |
testcase_42 | AC | 128 ms
110,680 KB |
testcase_43 | AC | 218 ms
173,884 KB |
testcase_44 | AC | 223 ms
173,448 KB |
ソースコード
import sys sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from random import randrange BASE = randrange(128, 256) MOD = 2147483629 class RollingHash: def __init__(self, target): self.N = len(target) self.table = [0] self.power = [1] for c in target: self.table += [(self.table[-1]*BASE)%MOD+c] self.power += [self.power[-1]*BASE%MOD] def hashing(self, s): h = 0 for c in s: h = h*BASE%MOD+c return h%MOD def hash_lr(self, l, r): return (self.table[r]-self.table[l]*self.power[r-l]%MOD)%MOD def find(self, s, start=0): h = self.hashing(s) for i in range(start, self.N-len(s)+1): if self.hash_lr(i, i+len(s)) == h: return i return -1 def find_all(self, s): res = [] h = self.hashing(s) for i in range(self.N-len(s)+1): if self.hash_lr(i, i+len(s)) == h: res.append(i) return res # def todd(s): # # print(s) # dd=[] # r=n-1 # while not s[r]:r-=1 # p=r # for i in range(r+1): # if s[i]: # dd.append((i-p)%n) # p=i # return dd n=II() aa=LI() s=[c==">" for c in SI()] s1=sum(s) t=[aa[i]>aa[i+1] for i in range(n-1)] t.append(aa[n-1]>aa[0]) t1=sum(t) if s1==t1: s.append(False) elif s1+1==t1: s.append(True) else: print(-1) exit() # sd=todd(s) # td=todd(t) # print(s) # print(t) # print(sd) # print(td) rh=RollingHash(t+t) hs=rh.hashing(s) for i in range(n): if rh.hash_lr(i,i+n)==hs: print(i) exit() print(-1)