結果
問題 | No.919 You Are A Project Manager |
ユーザー | mkawa2 |
提出日時 | 2022-04-06 23:24:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 246 ms / 3,000 ms |
コード長 | 3,254 bytes |
コンパイル時間 | 304 ms |
コンパイル使用メモリ | 82,300 KB |
実行使用メモリ | 80,196 KB |
最終ジャッジ日時 | 2024-05-05 20:10:20 |
合計ジャッジ時間 | 10,452 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 151 ms
77,824 KB |
testcase_01 | AC | 39 ms
52,816 KB |
testcase_02 | AC | 39 ms
52,864 KB |
testcase_03 | AC | 38 ms
52,736 KB |
testcase_04 | AC | 106 ms
77,532 KB |
testcase_05 | AC | 109 ms
77,476 KB |
testcase_06 | AC | 75 ms
76,484 KB |
testcase_07 | AC | 151 ms
78,780 KB |
testcase_08 | AC | 103 ms
77,636 KB |
testcase_09 | AC | 104 ms
77,312 KB |
testcase_10 | AC | 119 ms
77,732 KB |
testcase_11 | AC | 111 ms
77,632 KB |
testcase_12 | AC | 52 ms
64,384 KB |
testcase_13 | AC | 129 ms
78,144 KB |
testcase_14 | AC | 61 ms
69,760 KB |
testcase_15 | AC | 81 ms
76,716 KB |
testcase_16 | AC | 133 ms
78,060 KB |
testcase_17 | AC | 149 ms
77,560 KB |
testcase_18 | AC | 150 ms
77,540 KB |
testcase_19 | AC | 151 ms
77,480 KB |
testcase_20 | AC | 230 ms
79,488 KB |
testcase_21 | AC | 146 ms
77,764 KB |
testcase_22 | AC | 167 ms
78,656 KB |
testcase_23 | AC | 161 ms
78,424 KB |
testcase_24 | AC | 168 ms
78,960 KB |
testcase_25 | AC | 164 ms
78,556 KB |
testcase_26 | AC | 224 ms
79,360 KB |
testcase_27 | AC | 227 ms
79,692 KB |
testcase_28 | AC | 244 ms
80,128 KB |
testcase_29 | AC | 149 ms
77,440 KB |
testcase_30 | AC | 151 ms
77,504 KB |
testcase_31 | AC | 147 ms
77,456 KB |
testcase_32 | AC | 153 ms
77,824 KB |
testcase_33 | AC | 171 ms
78,972 KB |
testcase_34 | AC | 175 ms
78,988 KB |
testcase_35 | AC | 241 ms
80,000 KB |
testcase_36 | AC | 235 ms
80,128 KB |
testcase_37 | AC | 243 ms
80,000 KB |
testcase_38 | AC | 246 ms
80,196 KB |
testcase_39 | AC | 52 ms
64,640 KB |
testcase_40 | AC | 82 ms
76,680 KB |
testcase_41 | AC | 62 ms
70,912 KB |
testcase_42 | AC | 77 ms
76,748 KB |
testcase_43 | AC | 77 ms
76,416 KB |
testcase_44 | AC | 100 ms
77,248 KB |
testcase_45 | AC | 77 ms
76,416 KB |
testcase_46 | AC | 87 ms
76,544 KB |
testcase_47 | AC | 156 ms
78,572 KB |
testcase_48 | AC | 157 ms
78,420 KB |
testcase_49 | AC | 162 ms
78,484 KB |
testcase_50 | AC | 157 ms
78,560 KB |
testcase_51 | AC | 148 ms
78,488 KB |
testcase_52 | AC | 159 ms
78,776 KB |
testcase_53 | AC | 148 ms
78,868 KB |
testcase_54 | AC | 83 ms
76,672 KB |
testcase_55 | AC | 40 ms
52,864 KB |
testcase_56 | AC | 40 ms
53,376 KB |
testcase_57 | AC | 40 ms
53,888 KB |
ソースコード
import sys # sys.setrecursionlimit(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 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 class WaveletMatrix: def __init__(self, aa): self.dec = sorted(set(aa)) self.enc = {a: i for i, a in enumerate(self.dec)} aa = [self.enc[a] for a in aa] self.log = len(self.dec).bit_length() self.n = len(aa) self.bb = [[0] for _ in range(self.log)] for i in range(self.log)[::-1]: naa = [[], []] for a in aa: d = a >> i & 1 naa[d].append(a) self.bb[i].append(self.bb[i][-1]+d) aa = naa[0]+naa[1] self.fi = {} for i in range(self.n)[::-1]: self.fi[aa[i]] = i self.aa = aa def _move(self, i, idx, d): if d: return self.n-self.bb[i][-1]+self.bb[i][idx] return idx-self.bb[i][idx] def __getitem__(self, idx): res = 0 for i in range(self.log)[::-1]: d = self.bb[i][idx+1]-self.bb[i][idx] res |= d << i idx = self._move(i, idx, d) return self.dec[res] # count a in [0,r) def rank(self, a, r): a = self.enc[a] if a not in self.fi: return 0 for i in range(self.log)[::-1]: r = self._move(i, r, a >> i & 1) return r-self.fi[a] # index of ith(0-indexed) a def select(self, a, ith): a = self.enc[a] if a not in self.fi: return -1 idx = self.fi[a]+ith for i in range(self.log-1): d = a >> i & 1 l, r = -1, self.n-1 while l+1 < r: m = (l+r)//2 nxt = self.n-self.bb[i][-1]+self.bb[i][m+1] if d else m+1-self.bb[i][m+1] if nxt < idx+1: l = m else: r = m idx = r return idx # ith value in sorted [l,r) def quantile(self, l, r, ith): for i in range(self.log)[::-1]: c0 = r-l-(self.bb[i][r]-self.bb[i][l]) if c0 > ith: l, r = self._move(i, l, 0), self._move(i, r, 0) else: l, r = self._move(i, l, 1), self._move(i, r, 1) ith -= c0 return self.dec[self.aa[l+ith]] n = II() aa = LI() wm = WaveletMatrix(aa) ans = -inf for k in range(1, n+1): m = (k-1)//2 st = [0] t = 0 for r in range(n, k-1, -k): t += wm.quantile(r-k, r, m)*k st.append(max(t, st[-1])) ans = max(ans, st[-1]) s = 0 for l in range(0, n-k+1, k): s += wm.quantile(l, l+k, m)*k st.pop() ans = max(ans, s+st[-1]) # pDB(k, ans, st) print(ans)