結果
問題 | No.919 You Are A Project Manager |
ユーザー | kwm_t |
提出日時 | 2023-05-16 23:11:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,242 ms / 3,000 ms |
コード長 | 4,069 bytes |
コンパイル時間 | 2,881 ms |
コンパイル使用メモリ | 228,076 KB |
実行使用メモリ | 17,556 KB |
最終ジャッジ日時 | 2024-05-08 15:41:06 |
合計ジャッジ時間 | 29,238 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,216 ms
16,528 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 127 ms
6,268 KB |
testcase_05 | AC | 146 ms
6,400 KB |
testcase_06 | AC | 6 ms
5,376 KB |
testcase_07 | AC | 278 ms
8,836 KB |
testcase_08 | AC | 41 ms
5,376 KB |
testcase_09 | AC | 27 ms
5,376 KB |
testcase_10 | AC | 57 ms
5,376 KB |
testcase_11 | AC | 53 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 69 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 16 ms
5,376 KB |
testcase_16 | AC | 117 ms
6,140 KB |
testcase_17 | AC | 1,175 ms
17,552 KB |
testcase_18 | AC | 1,142 ms
17,176 KB |
testcase_19 | AC | 1,242 ms
16,532 KB |
testcase_20 | AC | 901 ms
16,188 KB |
testcase_21 | AC | 1,234 ms
16,528 KB |
testcase_22 | AC | 305 ms
9,216 KB |
testcase_23 | AC | 294 ms
8,956 KB |
testcase_24 | AC | 328 ms
9,600 KB |
testcase_25 | AC | 314 ms
9,088 KB |
testcase_26 | AC | 873 ms
14,988 KB |
testcase_27 | AC | 735 ms
14,224 KB |
testcase_28 | AC | 1,005 ms
16,148 KB |
testcase_29 | AC | 1,147 ms
17,556 KB |
testcase_30 | AC | 1,176 ms
17,304 KB |
testcase_31 | AC | 1,169 ms
17,552 KB |
testcase_32 | AC | 1,159 ms
17,432 KB |
testcase_33 | AC | 347 ms
9,216 KB |
testcase_34 | AC | 338 ms
9,344 KB |
testcase_35 | AC | 1,032 ms
16,404 KB |
testcase_36 | AC | 1,016 ms
16,664 KB |
testcase_37 | AC | 1,032 ms
16,532 KB |
testcase_38 | AC | 1,027 ms
16,532 KB |
testcase_39 | AC | 3 ms
5,376 KB |
testcase_40 | AC | 17 ms
5,376 KB |
testcase_41 | AC | 4 ms
5,376 KB |
testcase_42 | AC | 6 ms
5,376 KB |
testcase_43 | AC | 9 ms
5,376 KB |
testcase_44 | AC | 25 ms
5,376 KB |
testcase_45 | AC | 6 ms
5,376 KB |
testcase_46 | AC | 19 ms
5,376 KB |
testcase_47 | AC | 302 ms
8,956 KB |
testcase_48 | AC | 304 ms
8,960 KB |
testcase_49 | AC | 336 ms
9,216 KB |
testcase_50 | AC | 319 ms
9,348 KB |
testcase_51 | AC | 284 ms
8,828 KB |
testcase_52 | AC | 197 ms
7,424 KB |
testcase_53 | AC | 273 ms
8,572 KB |
testcase_54 | AC | 17 ms
5,376 KB |
testcase_55 | AC | 2 ms
5,376 KB |
testcase_56 | AC | 2 ms
5,376 KB |
testcase_57 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } struct Mo { int width; vector<int>left, right, order; vector<int>ans; //vector<long long>horder; int n, q; Mo(int _n, int _q) :n(_n), q(_q) { width = (int)sqrt(_n); order.resize(q); iota(all(order), 0); ans.resize(q); } // add,query[l,r) void query(vector<int> &l, vector<int> &r) { swap(left, l); swap(right, r); //horder.resize(q); //rep(i, q) horder[i] = hilbertorder(left[i], right[i]); } // run void run(const vector<int>&data) { sort(all(order), [&](int lh, int rh) { //return horder[lh] < horder[rh]; int lblock = left[lh] / width; int rblock = left[rh] / width; if (lblock != rblock)return lblock < rblock; if (lblock & 1) return right[lh] < right[rh]; return right[lh] > right[rh]; }); int nl = 0, nr = 0; multiset<int> x, y; auto add = [&](int idx) { x.insert(data[idx]); y.insert(*x.rbegin()); x.erase(x.find(*x.rbegin())); x.insert(*y.begin()); y.erase(y.begin()); if (x.size() > y.size() + 1) { y.insert(*x.rbegin()); x.erase(x.find(*x.rbegin())); } }; auto del = [&](int idx) { if (x.count(data[idx])) { x.erase(x.find(data[idx])); if (x.size() < y.size()) { x.insert(*y.begin()); y.erase(y.begin()); } } else { y.erase(y.find(data[idx])); if (x.size() > y.size() + 1) { y.insert(*x.rbegin()); x.erase(x.find(*x.rbegin())); } } }; auto ansset = [&](int idx) { ans[idx] = *x.rbegin(); }; for (auto idx : order) { while (nl > left[idx])add(--nl); while (nr < right[idx])add(nr++); while (nl < left[idx])del(nl++); while (nr > right[idx])del(--nr); ansset(idx); } } // TLEするときはこっちを使うと通るかも /*const int logn = 20; const int maxn = 1 << logn; long long hilbertorder(int x, int y) { long long d = 0; for (int s = 1 << logn - 1; s; s >>= 1) { bool rx = x & s, ry = y & s; d = d << 2 | rx * 3 ^ static_cast<int>(ry); if (ry) continue; if (rx) { x = maxn - x; y = maxn - y; } swap(x, y); } return d; }*/ }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int>a(n); rep(i, n)cin >> a[i]; long long ans = 0; map<P, int>mp; vector<int>l, r; rep2(i, 1, n + 1) { for (int j = 0; j + i <= n; j += i) { l.push_back(j); r.push_back(j + i); mp[{j, j + i}] = mp.size(); } if (0 == n % i)continue; for (int j = n; j - i >= 0; j -= i) { l.push_back(j - i); r.push_back(j); mp[{j - i, j}] = mp.size(); } } Mo mo(n, mp.size()); mo.query(l, r); mo.run(a); rep2(i, 1, n + 1) { vector<int>l, r; for (int j = 0; j + i <= n; j += i) { int idx = mp[{j, j + i}]; l.push_back(mo.ans[idx]); } for (int j = n; j - i >= 0; j -= i) { int idx = mp[{j - i, j}]; r.push_back(mo.ans[idx]); } vector<long long>sl(l.size() + 1), sr(r.size() + 1); rep(j, l.size())sl[j + 1] = sl[j] + l[j]; rep(j, l.size())chmax(sl[j + 1], sl[j]); rep(j, r.size())sr[j + 1] = sr[j] + r[j]; rep(j, r.size())chmax(sr[j + 1], sr[j]); int mx = n / i; rep(j, mx + 1) { long long sub = 0; sub += sl[j] - sl[0]; int k = mx - j; sub += sr[k] - sr[0]; chmax(ans, sub * i); } } cout << ans << endl; return 0; }