Submission #1082368

# Submission time Handle Problem Language Result Execution time Memory
1082368 2024-08-31T08:25:38 Z cpptowin Bigger segments (IZhO19_segments) C++17
100 / 100
100 ms 59988 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
int n,a[maxn],p[maxn];
pii f[maxn];
vii ke[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i,1,n) cin >> a[i],p[i] = p[i - 1] + a[i];
    pii now = {1,0};
    ke[1].pb(now);
    fo(i,1,n) 
    {
        for(auto it : ke[i]) maximize(now,it);
        f[i] = now;
        int lb = lower_bound(p + 1,p + n + 1,2 * p[i] - p[f[i].se]) - p;
        ke[lb].pb(f[i].fi + 1,i);
    }
    cout << f[n].fi;
}

Compilation message

segments.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
segments.cpp: In function 'int main()':
segments.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23872 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23728 KB Output is correct
8 Correct 11 ms 23968 KB Output is correct
9 Correct 12 ms 23840 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 23968 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23736 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23872 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23728 KB Output is correct
8 Correct 11 ms 23968 KB Output is correct
9 Correct 12 ms 23840 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 23968 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23736 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 12 ms 23896 KB Output is correct
17 Correct 11 ms 23896 KB Output is correct
18 Correct 12 ms 23952 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23956 KB Output is correct
21 Correct 11 ms 23896 KB Output is correct
22 Correct 10 ms 23896 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23868 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 11 ms 23896 KB Output is correct
29 Correct 11 ms 23892 KB Output is correct
30 Correct 12 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23872 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23728 KB Output is correct
8 Correct 11 ms 23968 KB Output is correct
9 Correct 12 ms 23840 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 23968 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23736 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 12 ms 23896 KB Output is correct
17 Correct 11 ms 23896 KB Output is correct
18 Correct 12 ms 23952 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23956 KB Output is correct
21 Correct 11 ms 23896 KB Output is correct
22 Correct 10 ms 23896 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23868 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 11 ms 23896 KB Output is correct
29 Correct 11 ms 23892 KB Output is correct
30 Correct 12 ms 23796 KB Output is correct
31 Correct 12 ms 24168 KB Output is correct
32 Correct 11 ms 24156 KB Output is correct
33 Correct 12 ms 23932 KB Output is correct
34 Correct 10 ms 24156 KB Output is correct
35 Correct 10 ms 24156 KB Output is correct
36 Correct 12 ms 24168 KB Output is correct
37 Correct 11 ms 24016 KB Output is correct
38 Correct 11 ms 23900 KB Output is correct
39 Correct 10 ms 23900 KB Output is correct
40 Correct 11 ms 24156 KB Output is correct
41 Correct 13 ms 23936 KB Output is correct
42 Correct 11 ms 23900 KB Output is correct
43 Correct 11 ms 23948 KB Output is correct
44 Correct 11 ms 23968 KB Output is correct
45 Correct 11 ms 24152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23872 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23728 KB Output is correct
8 Correct 11 ms 23968 KB Output is correct
9 Correct 12 ms 23840 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 23968 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23736 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 12 ms 23896 KB Output is correct
17 Correct 11 ms 23896 KB Output is correct
18 Correct 12 ms 23952 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23956 KB Output is correct
21 Correct 11 ms 23896 KB Output is correct
22 Correct 10 ms 23896 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23868 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 11 ms 23896 KB Output is correct
29 Correct 11 ms 23892 KB Output is correct
30 Correct 12 ms 23796 KB Output is correct
31 Correct 12 ms 24168 KB Output is correct
32 Correct 11 ms 24156 KB Output is correct
33 Correct 12 ms 23932 KB Output is correct
34 Correct 10 ms 24156 KB Output is correct
35 Correct 10 ms 24156 KB Output is correct
36 Correct 12 ms 24168 KB Output is correct
37 Correct 11 ms 24016 KB Output is correct
38 Correct 11 ms 23900 KB Output is correct
39 Correct 10 ms 23900 KB Output is correct
40 Correct 11 ms 24156 KB Output is correct
41 Correct 13 ms 23936 KB Output is correct
42 Correct 11 ms 23900 KB Output is correct
43 Correct 11 ms 23948 KB Output is correct
44 Correct 11 ms 23968 KB Output is correct
45 Correct 11 ms 24152 KB Output is correct
46 Correct 17 ms 29144 KB Output is correct
47 Correct 23 ms 29944 KB Output is correct
48 Correct 26 ms 30476 KB Output is correct
49 Correct 25 ms 31104 KB Output is correct
50 Correct 26 ms 30996 KB Output is correct
51 Correct 27 ms 30664 KB Output is correct
52 Correct 18 ms 27228 KB Output is correct
53 Correct 16 ms 25948 KB Output is correct
54 Correct 25 ms 29880 KB Output is correct
55 Correct 25 ms 30812 KB Output is correct
56 Correct 25 ms 30552 KB Output is correct
57 Correct 20 ms 29784 KB Output is correct
58 Correct 21 ms 30164 KB Output is correct
59 Correct 23 ms 30628 KB Output is correct
60 Correct 24 ms 30760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23872 KB Output is correct
3 Correct 12 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23728 KB Output is correct
8 Correct 11 ms 23968 KB Output is correct
9 Correct 12 ms 23840 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 23968 KB Output is correct
12 Correct 11 ms 23900 KB Output is correct
13 Correct 11 ms 23900 KB Output is correct
14 Correct 11 ms 23736 KB Output is correct
15 Correct 11 ms 23900 KB Output is correct
16 Correct 12 ms 23896 KB Output is correct
17 Correct 11 ms 23896 KB Output is correct
18 Correct 12 ms 23952 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 11 ms 23956 KB Output is correct
21 Correct 11 ms 23896 KB Output is correct
22 Correct 10 ms 23896 KB Output is correct
23 Correct 11 ms 23900 KB Output is correct
24 Correct 11 ms 23900 KB Output is correct
25 Correct 11 ms 23868 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
27 Correct 11 ms 23900 KB Output is correct
28 Correct 11 ms 23896 KB Output is correct
29 Correct 11 ms 23892 KB Output is correct
30 Correct 12 ms 23796 KB Output is correct
31 Correct 12 ms 24168 KB Output is correct
32 Correct 11 ms 24156 KB Output is correct
33 Correct 12 ms 23932 KB Output is correct
34 Correct 10 ms 24156 KB Output is correct
35 Correct 10 ms 24156 KB Output is correct
36 Correct 12 ms 24168 KB Output is correct
37 Correct 11 ms 24016 KB Output is correct
38 Correct 11 ms 23900 KB Output is correct
39 Correct 10 ms 23900 KB Output is correct
40 Correct 11 ms 24156 KB Output is correct
41 Correct 13 ms 23936 KB Output is correct
42 Correct 11 ms 23900 KB Output is correct
43 Correct 11 ms 23948 KB Output is correct
44 Correct 11 ms 23968 KB Output is correct
45 Correct 11 ms 24152 KB Output is correct
46 Correct 17 ms 29144 KB Output is correct
47 Correct 23 ms 29944 KB Output is correct
48 Correct 26 ms 30476 KB Output is correct
49 Correct 25 ms 31104 KB Output is correct
50 Correct 26 ms 30996 KB Output is correct
51 Correct 27 ms 30664 KB Output is correct
52 Correct 18 ms 27228 KB Output is correct
53 Correct 16 ms 25948 KB Output is correct
54 Correct 25 ms 29880 KB Output is correct
55 Correct 25 ms 30812 KB Output is correct
56 Correct 25 ms 30552 KB Output is correct
57 Correct 20 ms 29784 KB Output is correct
58 Correct 21 ms 30164 KB Output is correct
59 Correct 23 ms 30628 KB Output is correct
60 Correct 24 ms 30760 KB Output is correct
61 Correct 49 ms 49344 KB Output is correct
62 Correct 57 ms 50508 KB Output is correct
63 Correct 77 ms 53928 KB Output is correct
64 Correct 93 ms 57756 KB Output is correct
65 Correct 91 ms 59988 KB Output is correct
66 Correct 100 ms 57460 KB Output is correct
67 Correct 78 ms 50772 KB Output is correct
68 Correct 46 ms 37204 KB Output is correct
69 Correct 78 ms 53584 KB Output is correct
70 Correct 93 ms 59008 KB Output is correct
71 Correct 81 ms 57172 KB Output is correct
72 Correct 65 ms 54340 KB Output is correct
73 Correct 77 ms 57032 KB Output is correct
74 Correct 77 ms 58452 KB Output is correct
75 Correct 84 ms 58448 KB Output is correct