# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
473229 | Lam_lai_cuoc_doi | Bigger segments (IZhO19_segments) | C++17 | 337 ms | 138104 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define task "AWARDS"
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long;
using ld = long double;
constexpr int N = 5e3 + 5;
constexpr int Inf = 1e9 + 7;
template<class T>
void read(T &x){
x = 0;
register int c;
while((c = getchar()) && (c > '9'|| c < '0'));
for(;c >='0' && c <='9';c = getchar())
x = x * 10 + c - '0';
}
int n, dp[N][N];
ll a[N];
void Read()
{
//cin >> n;
read(n);
for (int i = 1; i <= n; ++i)
//cin >> a[i];
read(a[i]);
//reverse(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
a[i] += a[i - 1];
}
void Sub_1()
{
int ans(1);
for (int i = 1; i <= n; ++i)
{
dp[i][0] = 1;
for (int j = 1; j < i; ++j)
{
dp[i][j] = -Inf;
for (int t = j - 1; ~t; --t)
if (a[i] - a[j] >= a[j] - a[t])
dp[i][j] = max(dp[i][j], dp[j][t] + 1);
else
break;
if (i == n)
ans = max(ans, dp[i][j]);
}
}
cout << ans;
}
void Sub_2()
{
int ans(1);
for (int i = 1; i <= n; ++i)
{
dp[i][0] = 1;
dp[i][i] = -Inf;
for (int j = i - 1, t = i - 2; j; --j)
{
if (t >= j)
--t;
while (~t && a[i] - a[j] >= a[j] - a[t])
--t;
dp[i][j] = -Inf;
dp[i][j] = max(dp[i][j], dp[j][t + 1] + 1);
dp[i][j] = max(dp[i][j], dp[i][j + 1]);
}
dp[i][0] = max(dp[i][1], dp[i][0]);
if (i == n)
ans = max(ans, dp[i][0]);
}
cout << ans;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task ".INP", "r"))
{
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
Read();
if (n <= 200)
Sub_1();
else
Sub_2();
}
컴파일 시 표준 에러 (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... |