Submission #402657

# Submission time Handle Problem Language Result Execution time Memory
402657 2021-05-12T08:08:18 Z Ruxandra985 Bigger segments (IZhO19_segments) C++14
100 / 100
126 ms 14948 KB
#include <bits/stdc++.h>
#define DIMN 500010
using namespace std;
pair <int, int> dp[DIMN];
int v[DIMN];
long long sp[DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , i , st , dr , mid;
    fscanf (fin,"%d",&n);
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i]);
        sp[i] = v[i] + sp[i - 1];
        dp[i] = make_pair(1 ,  1);/// o secventa, incepe la 1 si se termina la i
    }

    for (i = 1 ; i <= n ; i++){

        if (i > 1){

            /// 1. iei o sg secventa de la 1 la i, initializat
            /// 2. prelungesti cu 1 secventa de la i - 1

            if (dp[i].first < dp[i - 1].first || (dp[i].first == dp[i - 1].first && dp[i].second < dp[i - 1].second)){
                dp[i].first = dp[i - 1].first;
                dp[i].second = dp[i - 1].second;
            }

        }

        /// acuma ma duc in unele mai mari

        st = i + 1;
        dr = n;
        while (st <= dr){
            mid = (st + dr)/2;

            if (sp[mid] - sp[i] >= sp[i] - sp[dp[i].second - 1]) /// e ok
                dr = mid - 1;
            else st = mid + 1;

        }

        /// solutia in st

        if (dp[st].first < dp[i].first + 1 || (dp[st].first == dp[i].first + 1 && i + 1 > dp[st].second)){
            dp[st].first = dp[i].first + 1;
            dp[st].second = i + 1;
        }


    }

    fprintf (fout,"%d",dp[n].first);


    return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     fscanf (fin,"%d",&n);
      |     ~~~~~~~^~~~~~~~~~~~~
segments.cpp:14:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         fscanf (fin,"%d",&v[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 380 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 380 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 14 ms 2600 KB Output is correct
47 Correct 17 ms 2640 KB Output is correct
48 Correct 18 ms 2980 KB Output is correct
49 Correct 18 ms 3204 KB Output is correct
50 Correct 18 ms 3248 KB Output is correct
51 Correct 21 ms 3148 KB Output is correct
52 Correct 11 ms 1728 KB Output is correct
53 Correct 7 ms 1084 KB Output is correct
54 Correct 16 ms 2488 KB Output is correct
55 Correct 19 ms 3236 KB Output is correct
56 Correct 14 ms 2636 KB Output is correct
57 Correct 15 ms 2620 KB Output is correct
58 Correct 15 ms 2612 KB Output is correct
59 Correct 15 ms 2852 KB Output is correct
60 Correct 15 ms 2856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 380 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 14 ms 2600 KB Output is correct
47 Correct 17 ms 2640 KB Output is correct
48 Correct 18 ms 2980 KB Output is correct
49 Correct 18 ms 3204 KB Output is correct
50 Correct 18 ms 3248 KB Output is correct
51 Correct 21 ms 3148 KB Output is correct
52 Correct 11 ms 1728 KB Output is correct
53 Correct 7 ms 1084 KB Output is correct
54 Correct 16 ms 2488 KB Output is correct
55 Correct 19 ms 3236 KB Output is correct
56 Correct 14 ms 2636 KB Output is correct
57 Correct 15 ms 2620 KB Output is correct
58 Correct 15 ms 2612 KB Output is correct
59 Correct 15 ms 2852 KB Output is correct
60 Correct 15 ms 2856 KB Output is correct
61 Correct 67 ms 11984 KB Output is correct
62 Correct 84 ms 11920 KB Output is correct
63 Correct 84 ms 12436 KB Output is correct
64 Correct 126 ms 14552 KB Output is correct
65 Correct 85 ms 14948 KB Output is correct
66 Correct 100 ms 14900 KB Output is correct
67 Correct 79 ms 11884 KB Output is correct
68 Correct 40 ms 6160 KB Output is correct
69 Correct 77 ms 11100 KB Output is correct
70 Correct 90 ms 14916 KB Output is correct
71 Correct 68 ms 12000 KB Output is correct
72 Correct 74 ms 12328 KB Output is correct
73 Correct 81 ms 13128 KB Output is correct
74 Correct 74 ms 13360 KB Output is correct
75 Correct 74 ms 13332 KB Output is correct