| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 863098 | LePhiPhat | Bigger segments (IZhO19_segments) | C++17 | 62 ms | 20068 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://codeforces.com/blog/entry/64479?#comment-484350
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
using namespace std;
#ifdef DEBUG
#include "debuge.cpp"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int) (x).size())
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ROF(i, a, b) for (int i = (a); i > (b); --i)
void LPP(int &test) {
int n;
cin >> n;
vll a(n + 1), p(n + 1);
vector<pll> dp(n + 1); // number of segment - sum
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[i];
// subtask 4
dp[0].fi = dp[0].se = 0;
for (int i = 1; i <= n; i++) {
dp[i].fi = 0;
dp[i].se = 5e15;
}
dp[0].fi = dp[0].se = 0;
for (int i = 0; i < n; i++) {
debug(i, dp[i]);
if (p[n] - p[i] >= dp[i].se) {
int lo = i, hi = n + 1;
while (lo + 1 < hi) {
int mi = (lo + hi) / 2;
if (p[mi] - p[i] >= dp[i].se) {
hi = mi;
} else {
lo = mi;
}
}
pll tmp;
tmp.fi = dp[i].fi;
tmp.se = dp[i].se + p[hi] - p[i];
if (tmp.fi > dp[hi].fi) {
dp[hi] = tmp;
} else if (tmp.fi == dp[hi].fi) {
dp[hi].se = min(tmp.se, dp[hi].se);
}
tmp.fi = dp[i].fi + 1;
tmp.se = p[hi] - p[i];
if (tmp.fi > dp[hi].fi) {
dp[hi] = tmp;
} else if (tmp.fi == dp[hi].fi) {
dp[hi].se = min(tmp.se, dp[hi].se);
}
debug(hi, dp[hi]);
}
int hi = i + 1;
pll tmp;
tmp.fi = dp[i].fi;
tmp.se = dp[i].se + p[hi] - p[i];
if (tmp.fi > dp[hi].fi) {
dp[hi] = tmp;
} else if (tmp.fi == dp[hi].fi) {
dp[hi].se = min(tmp.se, dp[hi].se);
}
tmp.fi = dp[i].fi + 1;
tmp.se = p[hi] - p[i];
if (tmp.se >= dp[i].se) {
if (tmp.fi > dp[hi].fi) {
dp[hi] = tmp;
} else if (tmp.fi == dp[hi].fi) {
dp[hi].se = min(tmp.se, dp[hi].se);
}
}
debug(i + 1, dp[i + 1]);
}
cout << dp[n].fi;
}
int32_t main() {
cin.tie(0) -> ios::sync_with_stdio(false);
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++) LPP(i);
}
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
*/
컴파일 시 표준 에러 (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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
