結果

問題 No.919 You Are A Project Manager
ユーザー polyomino_24polyomino_24
提出日時 2019-10-26 20:01:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,443 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 115,796 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-08-20 13:23:47
合計ジャッジ時間 52,219 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,371 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 24 ms
4,384 KB
testcase_05 AC 28 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 772 ms
4,376 KB
testcase_08 AC 81 ms
4,380 KB
testcase_09 AC 50 ms
4,376 KB
testcase_10 AC 121 ms
4,376 KB
testcase_11 AC 110 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 169 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 292 ms
4,376 KB
testcase_17 AC 505 ms
4,380 KB
testcase_18 AC 507 ms
4,380 KB
testcase_19 AC 1,378 ms
4,376 KB
testcase_20 TLE -
testcase_21 AC 1,367 ms
4,380 KB
testcase_22 AC 883 ms
4,380 KB
testcase_23 AC 849 ms
4,376 KB
testcase_24 AC 938 ms
4,376 KB
testcase_25 AC 885 ms
4,380 KB
testcase_26 TLE -
testcase_27 AC 2,481 ms
4,380 KB
testcase_28 TLE -
testcase_29 AC 504 ms
4,380 KB
testcase_30 AC 503 ms
4,376 KB
testcase_31 AC 385 ms
4,376 KB
testcase_32 AC 435 ms
4,380 KB
testcase_33 AC 1,029 ms
4,376 KB
testcase_34 AC 1,029 ms
4,376 KB
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 29 ms
4,376 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 8 ms
4,380 KB
testcase_43 AC 13 ms
4,380 KB
testcase_44 AC 44 ms
4,376 KB
testcase_45 AC 7 ms
4,376 KB
testcase_46 AC 35 ms
4,380 KB
testcase_47 AC 885 ms
4,380 KB
testcase_48 AC 868 ms
4,376 KB
testcase_49 AC 968 ms
4,380 KB
testcase_50 AC 879 ms
4,376 KB
testcase_51 AC 760 ms
4,380 KB
testcase_52 AC 515 ms
4,380 KB
testcase_53 AC 762 ms
4,376 KB
testcase_54 AC 28 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int Find_median(vector<int>a){
    sort(a.begin(),a.end());
    return a[a.size()/2];
}
//T(n) = T(n/5) + T() + O(n)
int kth_smallest(const vector<int>&a, int l, int r, int k){
    if(k <= 0 or r - l < k)return INT_MAX;
//    vector<int>med;
//    for(int i = l; i < r;){
//        vector<int>temp;
//        for(int j = 0; j < 5; j++){
//            if(i < r) temp.push_back(a[i++]);
//        }
//        med.push_back(Find_median(temp));
//    }
//    int medofmed = (med.size() == 1) ? med[0] :  kth_smallest(med, 0, (int) med.size(), (int) med.size() / 2);
    int medofmed = a[rand()%a.size()];
    vector<int> b,c,d;
    int c_size = 0;
    for (int i = l; i < r; i++){
        if(a[i] < medofmed){
            b.push_back(a[i]);
        }else if(a[i] == medofmed){
//            c.push_back(a[i]);
            c_size++;
        }else{
            d.push_back(a[i]);
        }
    }
    if(b.size() >= k){
        return kth_smallest(b, 0, (int) b.size(), k);
    }else if(b.size() + c_size >= k){
        return medofmed;
    }else{
        return kth_smallest(d, 0, (int) d.size(), k - (int) b.size() - (int) c_size);
    }
    return INT_MAX;
}
ll dp[2][10005];
ll rui[10005];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    ll ans = -(1LL<<60);
    set<int>st;
    rep(i,n)st.insert(i + 1);
    if(n > 90000){
        rep(i,100)st.erase(rand() % n + 1);
    }
    for(const int k : st){
        ll sum = 0;
        const int pos = (k - 1)/ 2 + 1;
        show(pos);
        int sz  = 0;
        for(int i = 0; i + k <= n; i+= k){
            dp[0][sz++] = ((ll)k * kth_smallest(a, i, i + k, pos));
        }
        sz = 0;
        for(int i = n; i - k >= 0; i-= k){
            dp[1][sz++] = ((ll)k * kth_smallest(a, i - k, i, pos));
        }
        rep(i,2){
            sum = max(sum,dp[i][0]);
            rep(j,sz-1){
                dp[i][j+1] += dp[i][j];
                sum = max(sum, dp[i][j+1]);
            }
        }
        rep(i,sz){
            if(i==0)rui[i] = dp[0][0];
            else rui[i] = max(rui[i-1], dp[0][i]);
        }
        rep(i,sz-1){
            sum = max(sum, rui[i] + dp[1][sz - 2 -i]);
        }
        show(k, sz, sum);
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
0