結果
| 問題 |
No.919 You Are A Project Manager
|
| ユーザー |
aajisaka
|
| 提出日時 | 2019-09-22 03:21:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,223 bytes |
| コンパイル時間 | 2,561 ms |
| コンパイル使用メモリ | 195,456 KB |
| 実行使用メモリ | 22,408 KB |
| 最終ジャッジ日時 | 2024-09-19 03:16:56 |
| 合計ジャッジ時間 | 22,895 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 20 TLE * 1 -- * 34 |
ソースコード
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author aajisaka
*/
#include<bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());
class CLCMs {
public:
void solve(istream& cin, ostream& cout) {
SPEED;
int n; cin >> n;
debug(n);
vector<int> a(n);
rep(i, n) {
cin >> a[i];
}
vector<P> vec;
for(int k=1; k<=n; k++) {
for(int i=0; i+k<=n; i+=k) {
vec.emplace_back(i,i+k);
}
for(int i=n; i-k>=0; i-=k) {
vec.emplace_back(i-k, i);
}
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
int s = vec.size();
debug(s);
map<P, int> mp;
priority_queue<int> que1;
priority_queue<int, vector<int>, greater<>> que2;
int now = -1;
int k = 0;
int cnt = 0;
for(int idx = 0; idx < s; idx++) {
int i = vec[idx].first;
int j = vec[idx].second;
if (now != i) {
while(!que1.empty()) que1.pop();
while(!que2.empty()) que2.pop();
que1.push(INT_MIN);
que2.push(INT_MAX);
k = i;
cnt = 0;
now = i;
}
while(k < j) {
if (cnt%2==0) {
que1.push(a[k]);
} else {
que2.push(a[k]);
}
if (que1.top() > que2.top()) {
int c1 = que1.top(); que1.pop();
int c2 = que2.top(); que2.pop();
que2.push(c1); que1.push(c2);
}
cnt++;
k++;
}
mp[P(i, j)] = que1.top();
}
debug(n);
ll ans = 0;
for(int j=1; j<=n; j++) {
ll no = 0;
ll ma = 0;
vector<ll> v1, v2;
v1.push_back(0);
for(int i=0; i+j<=n; i+=j) {
no += mp[P(i, i+j)];
chmax(ma, no);
v1.push_back(ma);
}
no = 0;
ma = 0;
v2.push_back(0);
for(int i=n; i-j>=0; i-=j) {
no += mp[P(i-j, i)];
chmax(ma, no);
v2.push_back(ma);
}
reverse(all(v2));
int r = v1.size();
rep(i, r) {
//debug(i, v1[i], v2[i]);
chmax(ans, (v1[i]+v2[i])*j);
}
}
cout << ans << endl;
}
};
signed main() {
CLCMs solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
aajisaka