답안 #529457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529457 2022-02-23T03:23:24 Z jiahng Cigle (COI21_cigle) C++14
0 / 100
73 ms 196488 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;
}

vi A[maxn];
int dp[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,1,N) FOR(r,l+1,N) 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){
			A[b].pb(l);
			R[l][b] = r;
		}
	}
	DEC(i,N,1){
		dp[i] = dp[i+1];
		FOR(b, i+1, N) if (R[i][b] != -1 && R[i][b] - i + 1 >= 2) {
			//~ if (i == 3) cout << b << ' ' << R[i][b] << ' ' << (A[b].end() - lbd(A[b], i)) << '\n';
			dp[i] = max(dp[i], dp[R[i][b] + 1] + (A[b].end() - lbd(A[b], i)));
		}
		//~ cout << dp[i] << ' ';
	}
	cout << dp[1];
	
}	

# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 196164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 196164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 73 ms 196488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 196164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 196164 KB Output isn't correct
2 Halted 0 ms 0 KB -