# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
407419 |
2021-05-18T23:23:33 Z |
534351 |
Cigle (COI21_cigle) |
C++17 |
|
47 ms |
2760 KB |
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
const int MAXN = 5013;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
int arr[MAXN], pref[MAXN];
int dp[MAXN][MAXN];
int ans;
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
cin >> N;
FOR(i, 0, N)
{
cin >> arr[i];
pref[i + 1] = pref[i] + arr[i];
}
dp[0][0] = 0;
FOR(i, 1, N + 1)
{
FOR(j, i, N + 1)
{
int c = 2 * pref[i - 1] - pref[j];
int idx = LB(pref, pref + N + 1, c) - pref;
if (pref[idx] == c)
{
//c(x, i-1) += 1 for all x <= idx.
// #warning check this
FOR(k, 0, idx)
{
dp[k][i - 1]++;
}
}
FOR(k, 0, i)
{
ckmax(dp[i][j], dp[k][i - 1]);
}
if (pref[idx] == c)
{
dp[idx][i - 1]++;
}
//i...j. that means you use i-1....j-1.
//count how many s i-2...k = si-1...c
//pref[i-1] - pref[k] = pref[j] - pref[i - 1].
//pref[k] = 2 pref[i - 1] - pref[j]
//find dp[i][j].
//dp[i][j] = max(dp[i][j], dp[k][i - 1] + c(k, i, j))
//c(k, i, j) is # of positions l such that s[k] +
//there's always some poition
}
}
FOR(i, 1, N + 1)
{
ckmax(ans, dp[i][N]);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
2760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |