| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1299316 | luvna | Hacker (BOI15_hac) | C++20 | 41 ms | 18908 KiB |
#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>
using namespace std;
bool START_ALLOC;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int MAX = 1e6 + 15;
int n, k;
int a[MAX];
ll pref[MAX];
ll f[MAX];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i-1] + a[i];
}
for(int i = n+1; i <= 2*n; i++){
a[i] = a[i-n];
pref[i] = pref[i-1] + a[i];
}
int k = (n + 1) / 2;
for(int i = k; i <= 2*n; i++){
f[i] = pref[i] - pref[i-k];
}
ll answer = 0;
deque<int> dq;
for(int i = 1; i <= 2*n; i++){
while(!dq.empty() && f[dq.back()] >= f[i]) dq.pop_back();
if(!dq.empty() && dq.front() <= i-k) dq.pop_front();
dq.push_back(i);
if(i >= k) maximize(answer, f[dq.front()]);
}
cout << answer << endl;
}
bool END_ALLOC;
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
cerr << "[Static Memory : " << fixed << setprecision(2) << (((&END_ALLOC) - (&START_ALLOC)) / (1024.0 * 1024.0)) << "mb]\n";
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
