結果
問題 | 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,232 ms / 3,000 ms |
コード長 | 4,069 bytes |
コンパイル時間 | 2,601 ms |
コンパイル使用メモリ | 226,700 KB |
実行使用メモリ | 17,460 KB |
最終ジャッジ日時 | 2024-12-14 20:34:18 |
合計ジャッジ時間 | 27,535 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,139 ms
16,404 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 123 ms
6,268 KB |
testcase_05 | AC | 129 ms
6,400 KB |
testcase_06 | AC | 5 ms
5,248 KB |
testcase_07 | AC | 264 ms
8,704 KB |
testcase_08 | AC | 37 ms
5,248 KB |
testcase_09 | AC | 26 ms
5,248 KB |
testcase_10 | AC | 55 ms
5,248 KB |
testcase_11 | AC | 49 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 65 ms
5,248 KB |
testcase_14 | AC | 4 ms
5,248 KB |
testcase_15 | AC | 15 ms
5,248 KB |
testcase_16 | AC | 111 ms
6,016 KB |
testcase_17 | AC | 1,087 ms
17,460 KB |
testcase_18 | AC | 1,078 ms
17,044 KB |
testcase_19 | AC | 1,148 ms
16,528 KB |
testcase_20 | AC | 856 ms
15,892 KB |
testcase_21 | AC | 1,170 ms
16,532 KB |
testcase_22 | AC | 291 ms
9,088 KB |
testcase_23 | AC | 278 ms
8,832 KB |
testcase_24 | AC | 316 ms
9,348 KB |
testcase_25 | AC | 284 ms
8,964 KB |
testcase_26 | AC | 830 ms
14,992 KB |
testcase_27 | AC | 707 ms
14,220 KB |
testcase_28 | AC | 943 ms
16,148 KB |
testcase_29 | AC | 1,232 ms
17,428 KB |
testcase_30 | AC | 1,064 ms
17,100 KB |
testcase_31 | AC | 1,095 ms
17,384 KB |
testcase_32 | AC | 1,088 ms
17,300 KB |
testcase_33 | AC | 310 ms
9,340 KB |
testcase_34 | AC | 327 ms
9,212 KB |
testcase_35 | AC | 972 ms
16,400 KB |
testcase_36 | AC | 961 ms
16,404 KB |
testcase_37 | AC | 961 ms
16,404 KB |
testcase_38 | AC | 969 ms
16,400 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 16 ms
5,248 KB |
testcase_41 | AC | 4 ms
5,248 KB |
testcase_42 | AC | 5 ms
5,248 KB |
testcase_43 | AC | 9 ms
5,248 KB |
testcase_44 | AC | 24 ms
5,248 KB |
testcase_45 | AC | 7 ms
5,248 KB |
testcase_46 | AC | 20 ms
5,248 KB |
testcase_47 | AC | 292 ms
8,964 KB |
testcase_48 | AC | 281 ms
8,960 KB |
testcase_49 | AC | 316 ms
9,216 KB |
testcase_50 | AC | 292 ms
9,216 KB |
testcase_51 | AC | 259 ms
8,704 KB |
testcase_52 | AC | 179 ms
7,296 KB |
testcase_53 | AC | 249 ms
8,580 KB |
testcase_54 | AC | 15 ms
5,248 KB |
testcase_55 | AC | 1 ms
5,248 KB |
testcase_56 | AC | 1 ms
5,248 KB |
testcase_57 | AC | 2 ms
5,248 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; }