답안 #503879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503879 2022-01-09T06:17:11 Z krit3379 Global Warming (CEOI18_glo) C++14
100 / 100
59 ms 4056 KB
#include<bits/stdc++.h>
using namespace std;
#define N 300005

int a[N],b[N],dp[N];
vector<int> s1,s2;

int main(){
    int n,d,i,ans=0;
    scanf("%d %d",&n,&d);
    for(i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=-a[i];
    for(i=1;i<=n;i++){
        int x=lower_bound(s1.begin(),s1.end(),a[i])-(s1.begin());
        if(x==s1.size())s1.push_back(a[i]);
        else s1[x]=a[i];
        dp[i]=x+1;
    }
    for(i=n;i>0;i--){
        int it=lower_bound(s2.begin(),s2.end(),b[i]+d)-(s2.begin());
        ans=max(ans,dp[i]+it);
        auto x=lower_bound(s2.begin(),s2.end(),b[i]);
        if(x==s2.end())s2.push_back(b[i]);
        else *x=b[i];
        //printf("i=%d dp=%d it=%d\n",i,dp1[i-1],it);
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:14:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         if(x==s1.size())s1.push_back(a[i]);
      |            ~^~~~~~~~~~~
glo.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d",&n,&d);
      |     ~~~~~^~~~~~~~~~~~~~~
glo.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for(i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=-a[i];
      |                      ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 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
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 2564 KB Output is correct
2 Correct 46 ms 2548 KB Output is correct
3 Correct 59 ms 2684 KB Output is correct
4 Correct 51 ms 2624 KB Output is correct
5 Correct 29 ms 3716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 892 KB Output is correct
2 Correct 11 ms 844 KB Output is correct
3 Correct 12 ms 844 KB Output is correct
4 Correct 7 ms 1228 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1112 KB Output is correct
7 Correct 10 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1484 KB Output is correct
2 Correct 23 ms 1416 KB Output is correct
3 Correct 52 ms 2528 KB Output is correct
4 Correct 34 ms 3800 KB Output is correct
5 Correct 21 ms 1996 KB Output is correct
6 Correct 23 ms 3652 KB Output is correct
7 Correct 28 ms 3648 KB Output is correct
8 Correct 17 ms 1384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 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 48 ms 2564 KB Output is correct
28 Correct 46 ms 2548 KB Output is correct
29 Correct 59 ms 2684 KB Output is correct
30 Correct 51 ms 2624 KB Output is correct
31 Correct 29 ms 3716 KB Output is correct
32 Correct 11 ms 892 KB Output is correct
33 Correct 11 ms 844 KB Output is correct
34 Correct 12 ms 844 KB Output is correct
35 Correct 7 ms 1228 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 8 ms 1112 KB Output is correct
38 Correct 10 ms 844 KB Output is correct
39 Correct 21 ms 1484 KB Output is correct
40 Correct 23 ms 1416 KB Output is correct
41 Correct 52 ms 2528 KB Output is correct
42 Correct 34 ms 3800 KB Output is correct
43 Correct 21 ms 1996 KB Output is correct
44 Correct 23 ms 3652 KB Output is correct
45 Correct 28 ms 3648 KB Output is correct
46 Correct 17 ms 1384 KB Output is correct
47 Correct 23 ms 1612 KB Output is correct
48 Correct 23 ms 1648 KB Output is correct
49 Correct 48 ms 2832 KB Output is correct
50 Correct 30 ms 4056 KB Output is correct
51 Correct 24 ms 3356 KB Output is correct
52 Correct 29 ms 3956 KB Output is correct
53 Correct 27 ms 3956 KB Output is correct
54 Correct 31 ms 3992 KB Output is correct
55 Correct 40 ms 2884 KB Output is correct