# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
530388 |
2022-02-25T09:26:19 Z |
jiahng |
Cigle (COI21_cigle) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define maxn 5001
#define getchar_unlocked _getchar_nolock
int N,D[maxn],ss[maxn];
inline int readInt() {
int x = 0;
char ch = getchar_unlocked();
while (ch < '0' || ch > '9') ch = getchar_unlocked();
while (ch >= '0' && ch <= '9'){
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar_unlocked();
}
return x;
}
vpi A[maxn];
int dp[maxn][maxn],R[maxn][maxn];
int32_t main() {
fast;
N = readInt();
FOR(i,1,N){
D[i] = readInt();
ss[i] = ss[i-1] + D[i];
}
mem(R, -1);
FOR(l,2,N) FOR(r,l+1,N-1) if ((ss[l-1] + ss[r]) % 2 == 0){
int ssb = (ss[l-1] + ss[r]) / 2;
int b = lower_bound(ss+l,ss+r,ssb) - ss;
if (ss[b] == ssb ){
//~ cout << l-1 << ' ' << b << ' ' << r << '\n';
A[b].pb(pi(l-1,r));
}
}
FOR(i,1,N) sort(all(A[i]), greater <pi>());
DEC(i,N,1) FOR(j,0,i-1) {
dp[i][j] = dp[i+1][j];
FOR(k,0,A[i].size()-1){
if (A[i][k].f > j){
dp[i][j] = max(dp[i][j], dp[max(i, A[i][k].s+1)][i] + k + 1);
}else break;
}
}
cout << dp[1][0];
}
Compilation message
cigle.cpp: In function 'll readInt()':
cigle.cpp:26:26: error: '_getchar_nolock' was not declared in this scope; did you mean 'getchar_unlocked'?
26 | #define getchar_unlocked _getchar_nolock
| ^~~~~~~~~~~~~~~
cigle.cpp:32:15: note: in expansion of macro 'getchar_unlocked'
32 | char ch = getchar_unlocked();
| ^~~~~~~~~~~~~~~~