結果
問題 | No.919 You Are A Project Manager |
ユーザー | mkawa2 |
提出日時 | 2022-04-06 23:24:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 227 ms / 3,000 ms |
コード長 | 3,254 bytes |
コンパイル時間 | 527 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 79,992 KB |
最終ジャッジ日時 | 2024-11-27 21:00:49 |
合計ジャッジ時間 | 10,115 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
77,568 KB |
testcase_01 | AC | 39 ms
52,736 KB |
testcase_02 | AC | 40 ms
52,736 KB |
testcase_03 | AC | 37 ms
52,608 KB |
testcase_04 | AC | 106 ms
77,272 KB |
testcase_05 | AC | 106 ms
77,148 KB |
testcase_06 | AC | 80 ms
76,160 KB |
testcase_07 | AC | 145 ms
78,360 KB |
testcase_08 | AC | 104 ms
77,324 KB |
testcase_09 | AC | 102 ms
77,056 KB |
testcase_10 | AC | 121 ms
77,400 KB |
testcase_11 | AC | 110 ms
77,752 KB |
testcase_12 | AC | 54 ms
64,000 KB |
testcase_13 | AC | 127 ms
78,188 KB |
testcase_14 | AC | 64 ms
69,248 KB |
testcase_15 | AC | 86 ms
76,288 KB |
testcase_16 | AC | 129 ms
77,440 KB |
testcase_17 | AC | 140 ms
77,184 KB |
testcase_18 | AC | 143 ms
77,952 KB |
testcase_19 | AC | 144 ms
77,824 KB |
testcase_20 | AC | 210 ms
79,872 KB |
testcase_21 | AC | 140 ms
77,568 KB |
testcase_22 | AC | 161 ms
78,456 KB |
testcase_23 | AC | 150 ms
78,292 KB |
testcase_24 | AC | 159 ms
78,600 KB |
testcase_25 | AC | 153 ms
78,296 KB |
testcase_26 | AC | 211 ms
79,104 KB |
testcase_27 | AC | 214 ms
79,824 KB |
testcase_28 | AC | 220 ms
79,744 KB |
testcase_29 | AC | 144 ms
77,568 KB |
testcase_30 | AC | 142 ms
77,184 KB |
testcase_31 | AC | 141 ms
77,312 KB |
testcase_32 | AC | 142 ms
77,696 KB |
testcase_33 | AC | 158 ms
78,860 KB |
testcase_34 | AC | 163 ms
78,736 KB |
testcase_35 | AC | 224 ms
79,744 KB |
testcase_36 | AC | 223 ms
79,744 KB |
testcase_37 | AC | 227 ms
79,744 KB |
testcase_38 | AC | 225 ms
79,992 KB |
testcase_39 | AC | 56 ms
64,256 KB |
testcase_40 | AC | 87 ms
76,416 KB |
testcase_41 | AC | 67 ms
71,424 KB |
testcase_42 | AC | 81 ms
76,288 KB |
testcase_43 | AC | 80 ms
76,672 KB |
testcase_44 | AC | 102 ms
76,800 KB |
testcase_45 | AC | 82 ms
76,288 KB |
testcase_46 | AC | 90 ms
76,544 KB |
testcase_47 | AC | 154 ms
78,316 KB |
testcase_48 | AC | 152 ms
78,424 KB |
testcase_49 | AC | 159 ms
78,488 KB |
testcase_50 | AC | 154 ms
78,300 KB |
testcase_51 | AC | 143 ms
78,616 KB |
testcase_52 | AC | 151 ms
78,520 KB |
testcase_53 | AC | 140 ms
78,364 KB |
testcase_54 | AC | 84 ms
76,564 KB |
testcase_55 | AC | 38 ms
52,992 KB |
testcase_56 | AC | 38 ms
53,248 KB |
testcase_57 | AC | 38 ms
53,504 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)