답안 #701650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701650 2023-02-21T16:47:03 Z jennierubyjane Bigger segments (IZhO19_segments) C++14
37 / 100
54 ms 28064 KB
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, b) for (int i = 0, _b = (b); i < _b; i++)
#define ii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define next ____next
#define prev ____prev
#define left ____left
#define right ___right
#define lcm ___lcm
#define index ____index
using namespace std;

template<class M> M myabs(M x) {
        return x < 0 ? -x : x;
}
template<class M1, class M2> bool minimize(M1 &x, const M2 &y) {
        if (x > y) {x = y; return true;} return false;
}
template<class M1, class M2> bool maximize(M1 &x, const M2 &y) {
        if (x < y) {x = y; return true;} return false;
}

const int INF = (int)1e9 + 7;
const ll INFLL = (ll)1e18 + 7LL;

const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

mt19937 rd(time(0));
/**
ii = pair<int, int>
FOR(i, a, b): a, b == int
**/

#define MAX 100100

int n, a[MAX];
ll pref[MAX];

ll sum(int l, int r) {
        return pref[r] - pref[l - 1];
}

int f[3030][3030];
void sub1() {
        FOR(i, 1, n) {
            int j = i - 1;
            int suff_max = i == 1 ? 0 : -INF;
            FOR(k, i, n) {
                while (j >= 1 && sum(j, i - 1) <= sum(i, k)) {
                    maximize(suff_max, f[j][i - 1]);
                    j--;
                }
                f[i][k] = suff_max + 1;
            }
        }
        int res = 0;
        FOR(i, 1, n) maximize(res, f[i][n]);
        cout << res;
}

void solve() {
        cin >> n;
        FOR(i, 1, n) cin >> a[i];

//        FOR(i, 1, n) a[i] = 1 + (rd() % (10));
//        FOR(i, 1, n) cout << a[i] << " "; cout << "\n";

        FOR(i, 1, n) pref[i] = pref[i - 1] + a[i];
        if (n <= 3000) {sub1(); return;}
        //sub1(); cout << " ";
        int ans = 0;
        FOR(i, 1, n) {
            ll cur = pref[i];
            for (int l = 1, j = i; ; l++) {
                j = lower_bound(pref + 1, pref + 1 + n, cur + pref[j]) - pref;
                maximize(ans, l);
                if (j > n) break;
                cur = pref[j] - cur;
            } //cout << "\n";
        }
        cout << ans;
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        
        int t = 1; //cin >> t;
        while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 2 ms 2828 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 1 ms 2772 KB Output is correct
26 Correct 2 ms 2800 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2864 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 1 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 2 ms 2828 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 1 ms 2772 KB Output is correct
26 Correct 2 ms 2800 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2864 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 1 ms 2772 KB Output is correct
31 Correct 22 ms 27992 KB Output is correct
32 Correct 21 ms 27988 KB Output is correct
33 Correct 28 ms 28060 KB Output is correct
34 Correct 29 ms 28052 KB Output is correct
35 Correct 23 ms 28020 KB Output is correct
36 Correct 38 ms 28064 KB Output is correct
37 Correct 30 ms 22080 KB Output is correct
38 Correct 16 ms 16168 KB Output is correct
39 Correct 51 ms 28004 KB Output is correct
40 Correct 23 ms 28060 KB Output is correct
41 Correct 40 ms 27980 KB Output is correct
42 Correct 22 ms 28008 KB Output is correct
43 Correct 54 ms 28032 KB Output is correct
44 Correct 28 ms 27988 KB Output is correct
45 Correct 24 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 2 ms 2828 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 1 ms 2772 KB Output is correct
26 Correct 2 ms 2800 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2864 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 1 ms 2772 KB Output is correct
31 Correct 22 ms 27992 KB Output is correct
32 Correct 21 ms 27988 KB Output is correct
33 Correct 28 ms 28060 KB Output is correct
34 Correct 29 ms 28052 KB Output is correct
35 Correct 23 ms 28020 KB Output is correct
36 Correct 38 ms 28064 KB Output is correct
37 Correct 30 ms 22080 KB Output is correct
38 Correct 16 ms 16168 KB Output is correct
39 Correct 51 ms 28004 KB Output is correct
40 Correct 23 ms 28060 KB Output is correct
41 Correct 40 ms 27980 KB Output is correct
42 Correct 22 ms 28008 KB Output is correct
43 Correct 54 ms 28032 KB Output is correct
44 Correct 28 ms 27988 KB Output is correct
45 Correct 24 ms 27988 KB Output is correct
46 Correct 8 ms 1492 KB Output is correct
47 Incorrect 12 ms 1416 KB Output isn't correct
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 2772 KB Output is correct
17 Correct 2 ms 2828 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 1 ms 2772 KB Output is correct
26 Correct 2 ms 2800 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2864 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 1 ms 2772 KB Output is correct
31 Correct 22 ms 27992 KB Output is correct
32 Correct 21 ms 27988 KB Output is correct
33 Correct 28 ms 28060 KB Output is correct
34 Correct 29 ms 28052 KB Output is correct
35 Correct 23 ms 28020 KB Output is correct
36 Correct 38 ms 28064 KB Output is correct
37 Correct 30 ms 22080 KB Output is correct
38 Correct 16 ms 16168 KB Output is correct
39 Correct 51 ms 28004 KB Output is correct
40 Correct 23 ms 28060 KB Output is correct
41 Correct 40 ms 27980 KB Output is correct
42 Correct 22 ms 28008 KB Output is correct
43 Correct 54 ms 28032 KB Output is correct
44 Correct 28 ms 27988 KB Output is correct
45 Correct 24 ms 27988 KB Output is correct
46 Correct 8 ms 1492 KB Output is correct
47 Incorrect 12 ms 1416 KB Output isn't correct
48 Halted 0 ms 0 KB -