답안 #989092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989092 2024-05-27T13:58:25 Z armashka Bigger segments (IZhO19_segments) C++17
37 / 100
180 ms 141660 KB
#include<bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ft first
#define sd second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
const int N = 1e6 + 10;
const int M = 2e7 + 5;
const int B = 316;
const ll msize = 2;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
const long double Phi = acos(-1);
const long long inf = 2e18;
const vector <pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

ll binmul(ll x, ll ti, ll m);
ll binpow(ll x, ll ti, ll m);

ll n, a[3005], dp[3005][3005], pref[3005], suf[3005][3005];

const void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> a[i], pref[i] = pref[i - 1] + a[i];

    for (int i = 0; i <= n; ++ i) {
        for (int j = 0; j <= n; ++ j) {
            dp[i][j] = suf[i][j] = -inf;
        }
    }

    for (int i = 1; i <= n; ++ i) dp[1][i] = 1;

    suf[1][1] = 1;

    for (int i = 2; i <= n; ++ i) {
        for (int j = i; j >= 1; -- j) {
            // for (int k = j - 1; k >= 1; -- k) {
            //     ll sum1 = pref[i] - pref[j - 1];
            //     ll sum2 = pref[j - 1] - pref[k - 1];

            //     if (sum2 <= sum1) {
            //         dp[j][i] = max(dp[j][i], dp[k][j - 1] + 1);
            //     }
            // }  

            int l = 1, r = j - 1, k = -1;
            while (l <= r) {
                int mid = (l + r) / 2;
                if (pref[j - 1] - pref[mid - 1] <= pref[i] - pref[j - 1]) r = mid - 1, k = mid;
                else l = mid + 1;
            }

            if (k != -1) dp[j][i] = max(dp[j][i], suf[k][j - 1] + 1);
        }
        suf[i][i] = dp[i][i];
        for (int j = i - 1; j >= 1; -- j) 
            suf[j][i] = max(dp[j][i], suf[j + 1][i]);
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++ i) ans = max(ans, dp[i][n]);
    cout << ans;
}  
                                  
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    srand(time(NULL));

    // file("maze");

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tt = 1;
    // cin >> tt;
    for (int i = 1; i <= tt; ++ i) {
        solve();
    }

    #ifndef ONLINE_JUDGE
    cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
} 


// Template functions
ll binmul(ll x, ll ti, ll m) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= m; res %= m;} return res;}
ll binpow(ll x, ll ti, ll m) { ll res = 1;while (ti){if(ti & 1)(res *= x)%=m;(x*=x)%=m;ti >>= 1; x %= m; res %= m;} return res;}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 13660 KB Output is correct
18 Correct 5 ms 12380 KB Output is correct
19 Correct 4 ms 13884 KB Output is correct
20 Correct 4 ms 13660 KB Output is correct
21 Correct 5 ms 13660 KB Output is correct
22 Correct 3 ms 11868 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 5 ms 13728 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 6 ms 12516 KB Output is correct
27 Correct 4 ms 12380 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 12380 KB Output is correct
30 Correct 4 ms 15080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 13660 KB Output is correct
18 Correct 5 ms 12380 KB Output is correct
19 Correct 4 ms 13884 KB Output is correct
20 Correct 4 ms 13660 KB Output is correct
21 Correct 5 ms 13660 KB Output is correct
22 Correct 3 ms 11868 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 5 ms 13728 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 6 ms 12516 KB Output is correct
27 Correct 4 ms 12380 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 12380 KB Output is correct
30 Correct 4 ms 15080 KB Output is correct
31 Correct 155 ms 141532 KB Output is correct
32 Correct 139 ms 141660 KB Output is correct
33 Correct 156 ms 141564 KB Output is correct
34 Correct 142 ms 141648 KB Output is correct
35 Correct 157 ms 141652 KB Output is correct
36 Correct 180 ms 141648 KB Output is correct
37 Correct 128 ms 118100 KB Output is correct
38 Correct 88 ms 80580 KB Output is correct
39 Correct 180 ms 141648 KB Output is correct
40 Correct 164 ms 141660 KB Output is correct
41 Correct 143 ms 141568 KB Output is correct
42 Correct 145 ms 141648 KB Output is correct
43 Correct 165 ms 141652 KB Output is correct
44 Correct 148 ms 141596 KB Output is correct
45 Correct 156 ms 141652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 13660 KB Output is correct
18 Correct 5 ms 12380 KB Output is correct
19 Correct 4 ms 13884 KB Output is correct
20 Correct 4 ms 13660 KB Output is correct
21 Correct 5 ms 13660 KB Output is correct
22 Correct 3 ms 11868 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 5 ms 13728 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 6 ms 12516 KB Output is correct
27 Correct 4 ms 12380 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 12380 KB Output is correct
30 Correct 4 ms 15080 KB Output is correct
31 Correct 155 ms 141532 KB Output is correct
32 Correct 139 ms 141660 KB Output is correct
33 Correct 156 ms 141564 KB Output is correct
34 Correct 142 ms 141648 KB Output is correct
35 Correct 157 ms 141652 KB Output is correct
36 Correct 180 ms 141648 KB Output is correct
37 Correct 128 ms 118100 KB Output is correct
38 Correct 88 ms 80580 KB Output is correct
39 Correct 180 ms 141648 KB Output is correct
40 Correct 164 ms 141660 KB Output is correct
41 Correct 143 ms 141568 KB Output is correct
42 Correct 145 ms 141648 KB Output is correct
43 Correct 165 ms 141652 KB Output is correct
44 Correct 148 ms 141596 KB Output is correct
45 Correct 156 ms 141652 KB Output is correct
46 Correct 2 ms 11100 KB Output is correct
47 Incorrect 84 ms 95424 KB Output isn't correct
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2652 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 13660 KB Output is correct
18 Correct 5 ms 12380 KB Output is correct
19 Correct 4 ms 13884 KB Output is correct
20 Correct 4 ms 13660 KB Output is correct
21 Correct 5 ms 13660 KB Output is correct
22 Correct 3 ms 11868 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 5 ms 13728 KB Output is correct
25 Correct 5 ms 13660 KB Output is correct
26 Correct 6 ms 12516 KB Output is correct
27 Correct 4 ms 12380 KB Output is correct
28 Correct 4 ms 13660 KB Output is correct
29 Correct 4 ms 12380 KB Output is correct
30 Correct 4 ms 15080 KB Output is correct
31 Correct 155 ms 141532 KB Output is correct
32 Correct 139 ms 141660 KB Output is correct
33 Correct 156 ms 141564 KB Output is correct
34 Correct 142 ms 141648 KB Output is correct
35 Correct 157 ms 141652 KB Output is correct
36 Correct 180 ms 141648 KB Output is correct
37 Correct 128 ms 118100 KB Output is correct
38 Correct 88 ms 80580 KB Output is correct
39 Correct 180 ms 141648 KB Output is correct
40 Correct 164 ms 141660 KB Output is correct
41 Correct 143 ms 141568 KB Output is correct
42 Correct 145 ms 141648 KB Output is correct
43 Correct 165 ms 141652 KB Output is correct
44 Correct 148 ms 141596 KB Output is correct
45 Correct 156 ms 141652 KB Output is correct
46 Correct 2 ms 11100 KB Output is correct
47 Incorrect 84 ms 95424 KB Output isn't correct
48 Halted 0 ms 0 KB -