結果
| 問題 |
No.919 You Are A Project Manager
|
| コンテスト | |
| ユーザー |
polyomino_24
|
| 提出日時 | 2019-10-26 19:59:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,443 bytes |
| コンパイル時間 | 1,520 ms |
| コンパイル使用メモリ | 135,076 KB |
| 最終ジャッジ日時 | 2025-01-08 01:58:11 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 TLE * 7 |
ソースコード
#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;
}
polyomino_24