Submission #715447

# Submission time Handle Problem Language Result Execution time Memory
715447 2023-03-26T18:21:58 Z MDSPro Bigger segments (IZhO19_segments) C++17
37 / 100
1500 ms 3412 KB
// MDSPro
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include "bits/stdc++.h"
#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(x...) 42
#endif
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using ld = long double;

const ld PI = 3.141592653589793;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFLL = 4e18;
const double EPS = 1e-9;
const int MAXN = 1000*1007;

void solve(int NT){
    int n; cin >> n;
    vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i];

    int ans;
    vector dp(n+1,INFLL); dp[0] = 0;
    vector opt(n+1,1);
    for(int i = 1; i <= n; ++i){
        vector old = dp;
        vector best = opt;

        dp.assign(n+1,INFLL); opt.assign(n+1,n-1);
        debug(old);
        for(int j = n; j >= 1; --j){
            int l = best[j];
            int r = (j+1 > n ? j : min(opt[j+1],j));
            ll sum = 0; for(int k = j; k > r; --k) sum += a[k-1];
            for(int k = r; k >= l; --k){
                sum += a[k-1];

                if(sum >= old[k-1] && sum < dp[j]) {
                    dp[j] = sum;
                    opt[j] = k;
                }
            }
            debug(i,j,sum);
        }
        debug(dp);
        debug(opt);
        if(dp[n] == INFLL) break;
        ans = i;
    }

    cout << ans;
}

// #define TESTCASES
int main() {
    cin.tie(0)->sync_with_stdio(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
    
    int t = 1;
    #ifdef TESTCASES
        cin >> t;
    #endif
    
    for(int i = 1; i <= t; ++i){
        solve(i);
        cout << "\n";
    }
}

Compilation message

segments.cpp: In function 'void solve(int)':
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
   10 |     #define debug(x...) 42
      |                         ^~
segments.cpp:37:9: note: in expansion of macro 'debug'
   37 |         debug(old);
      |         ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
   10 |     #define debug(x...) 42
      |                         ^~
segments.cpp:50:13: note: in expansion of macro 'debug'
   50 |             debug(i,j,sum);
      |             ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
   10 |     #define debug(x...) 42
      |                         ^~
segments.cpp:52:9: note: in expansion of macro 'debug'
   52 |         debug(dp);
      |         ^~~~~
segments.cpp:10:25: warning: statement has no effect [-Wunused-value]
   10 |     #define debug(x...) 42
      |                         ^~
segments.cpp:53:9: note: in expansion of macro 'debug'
   53 |         debug(opt);
      |         ^~~~~
segments.cpp:58:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     cout << ans;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 5 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 10 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 3 ms 212 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 5 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 10 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 3 ms 212 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 8 ms 340 KB Output is correct
32 Correct 11 ms 404 KB Output is correct
33 Correct 25 ms 340 KB Output is correct
34 Correct 949 ms 408 KB Output is correct
35 Correct 55 ms 340 KB Output is correct
36 Correct 23 ms 340 KB Output is correct
37 Correct 16 ms 416 KB Output is correct
38 Correct 12 ms 340 KB Output is correct
39 Correct 34 ms 340 KB Output is correct
40 Correct 30 ms 340 KB Output is correct
41 Correct 72 ms 396 KB Output is correct
42 Correct 604 ms 396 KB Output is correct
43 Correct 442 ms 392 KB Output is correct
44 Correct 64 ms 340 KB Output is correct
45 Correct 102 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 5 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 10 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 3 ms 212 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 8 ms 340 KB Output is correct
32 Correct 11 ms 404 KB Output is correct
33 Correct 25 ms 340 KB Output is correct
34 Correct 949 ms 408 KB Output is correct
35 Correct 55 ms 340 KB Output is correct
36 Correct 23 ms 340 KB Output is correct
37 Correct 16 ms 416 KB Output is correct
38 Correct 12 ms 340 KB Output is correct
39 Correct 34 ms 340 KB Output is correct
40 Correct 30 ms 340 KB Output is correct
41 Correct 72 ms 396 KB Output is correct
42 Correct 604 ms 396 KB Output is correct
43 Correct 442 ms 392 KB Output is correct
44 Correct 64 ms 340 KB Output is correct
45 Correct 102 ms 396 KB Output is correct
46 Execution timed out 1576 ms 3412 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 5 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 10 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 3 ms 212 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 8 ms 340 KB Output is correct
32 Correct 11 ms 404 KB Output is correct
33 Correct 25 ms 340 KB Output is correct
34 Correct 949 ms 408 KB Output is correct
35 Correct 55 ms 340 KB Output is correct
36 Correct 23 ms 340 KB Output is correct
37 Correct 16 ms 416 KB Output is correct
38 Correct 12 ms 340 KB Output is correct
39 Correct 34 ms 340 KB Output is correct
40 Correct 30 ms 340 KB Output is correct
41 Correct 72 ms 396 KB Output is correct
42 Correct 604 ms 396 KB Output is correct
43 Correct 442 ms 392 KB Output is correct
44 Correct 64 ms 340 KB Output is correct
45 Correct 102 ms 396 KB Output is correct
46 Execution timed out 1576 ms 3412 KB Time limit exceeded
47 Halted 0 ms 0 KB -