Submission #371001

# Submission time Handle Problem Language Result Execution time Memory
371001 2021-02-25T12:26:20 Z ntabc05101 Global Warming (CEOI18_glo) C++14
100 / 100
71 ms 5232 KB
#ifndef LOCAL
#define NDEBUG 1
#endif // LOCAL
#include<bits/stdc++.h>

#define taskname ""
#define i64_ int64_t

int main() {
        if (fopen(taskname".inp", "r")) {
                freopen(taskname".inp", "r", stdin);
                freopen(taskname".out", "w", stdout);
        }
        else if (fopen(taskname".in", "r")) {
                freopen(taskname".in", "r", stdin);
                freopen(taskname".out", "w", stdout);
        }

        std::ios_base::sync_with_stdio(0); std::cin.tie(0);

        int n, x; std::cin>>n>>x;
        i64_ a[n];
        for (int i=0; i<n; ++i) std::cin>>a[i];

        int result=0;

        std::vector<int> lis;
        int dp[n];
        for (int i=0; i<n; ++i) {
                int pos=std::lower_bound(begin(lis), end(lis), a[i])-begin(lis);
                if (pos==lis.size()) lis.emplace_back(a[i]);
                else lis[pos]=a[i];

                dp[i]=1+pos;
                result=std::max(result, dp[i]);
        }

        lis.clear();
        for (int i=n-1; i>=0; --i) {
                int pos=std::lower_bound(begin(lis), end(lis), -a[i])-begin(lis);
                int j=std::lower_bound(begin(lis), end(lis), -a[i]+x)-begin(lis);

                if (pos==lis.size()) lis.emplace_back(-a[i]);
                else lis[pos]=-a[i];
                result=std::max(result, dp[i]+j);
        }

        std::cout<<result<<"\n";

        return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                 if (pos==lis.size()) lis.emplace_back(a[i]);
      |                     ~~~^~~~~~~~~~~~
glo.cpp:43:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |                 if (pos==lis.size()) lis.emplace_back(-a[i]);
      |                     ~~~^~~~~~~~~~~~
glo.cpp:11:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   11 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:12:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   12 |                 freopen(taskname".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:15:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |                 freopen(taskname".in", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |                 freopen(taskname".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4588 KB Output is correct
2 Correct 60 ms 4588 KB Output is correct
3 Correct 61 ms 4588 KB Output is correct
4 Correct 61 ms 4688 KB Output is correct
5 Correct 33 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1388 KB Output is correct
2 Correct 14 ms 1388 KB Output is correct
3 Correct 14 ms 1388 KB Output is correct
4 Correct 8 ms 1516 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 8 ms 1516 KB Output is correct
7 Correct 12 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2540 KB Output is correct
2 Correct 26 ms 2540 KB Output is correct
3 Correct 52 ms 4716 KB Output is correct
4 Correct 34 ms 4332 KB Output is correct
5 Correct 16 ms 2416 KB Output is correct
6 Correct 28 ms 4332 KB Output is correct
7 Correct 35 ms 4976 KB Output is correct
8 Correct 22 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 71 ms 4588 KB Output is correct
28 Correct 60 ms 4588 KB Output is correct
29 Correct 61 ms 4588 KB Output is correct
30 Correct 61 ms 4688 KB Output is correct
31 Correct 33 ms 4460 KB Output is correct
32 Correct 15 ms 1388 KB Output is correct
33 Correct 14 ms 1388 KB Output is correct
34 Correct 14 ms 1388 KB Output is correct
35 Correct 8 ms 1516 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 8 ms 1516 KB Output is correct
38 Correct 12 ms 1388 KB Output is correct
39 Correct 26 ms 2540 KB Output is correct
40 Correct 26 ms 2540 KB Output is correct
41 Correct 52 ms 4716 KB Output is correct
42 Correct 34 ms 4332 KB Output is correct
43 Correct 16 ms 2416 KB Output is correct
44 Correct 28 ms 4332 KB Output is correct
45 Correct 35 ms 4976 KB Output is correct
46 Correct 22 ms 2540 KB Output is correct
47 Correct 29 ms 2540 KB Output is correct
48 Correct 33 ms 2540 KB Output is correct
49 Correct 70 ms 4588 KB Output is correct
50 Correct 34 ms 4340 KB Output is correct
51 Correct 35 ms 3440 KB Output is correct
52 Correct 33 ms 4460 KB Output is correct
53 Correct 29 ms 4460 KB Output is correct
54 Correct 37 ms 5232 KB Output is correct
55 Correct 50 ms 4716 KB Output is correct