답안 #826309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826309 2023-08-15T12:35:19 Z gagik_2007 Global Warming (CEOI18_glo) C++17
100 / 100
59 ms 5852 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define ff first
#define ss second

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=5007;
ll n,m,k;
vector<int>a;

vector<int>LIS_suffix(vector<int>&a){
    vector<int>dp;
    vector<int>ans;
    for(int i=0;i<a.size();i++){
        auto it=lower_bound(dp.begin(),dp.end(),a[i]);
        if(it==dp.end()){
            dp.push_back(a[i]);
        }
        else{
            dp[it-dp.begin()]=a[i];
        }
        it=lower_bound(dp.begin(),dp.end(),a[i+1]+k);
        if(it==dp.begin()){
            ans.push_back(0);
        }
        else{
            it--;
            ans.push_back(it-dp.begin()+1);
        }
    }
    return ans;
}

vector<int>LIS_prefix(vector<int>&a){
    vector<int>dp;
    vector<int>ans;
    for(int i=0;i<a.size();i++){
        auto it=lower_bound(dp.begin(),dp.end(),a[i]);
        if(it==dp.end()){
            dp.push_back(a[i]);
            ans.push_back(dp.size());
        }
        else{
            dp[it-dp.begin()]=a[i];
            ans.push_back(it-dp.begin()+1);
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n>>k;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int>pf=LIS_prefix(a);
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        a[i]*=-1;
    }
    vector<int>sf=LIS_suffix(a);
    reverse(sf.begin(),sf.end());
    // for(int i=0;i<n;i++){
    //     cout<<i<<": "<<pf[i]<<" "<<sf[i]<<endl;
    // }
    int ans=pf.back();
    for(int i=1;i<n;i++){
        // cout<<pf[i-1]+sf[i]<<" ";
        ans=max(ans,pf[i-1]+sf[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

glo.cpp: In function 'std::vector<int> LIS_suffix(std::vector<int>&)':
glo.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
glo.cpp: In function 'std::vector<int> LIS_prefix(std::vector<int>&)':
glo.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5316 KB Output is correct
2 Correct 59 ms 5304 KB Output is correct
3 Correct 58 ms 5316 KB Output is correct
4 Correct 59 ms 5352 KB Output is correct
5 Correct 23 ms 4920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1536 KB Output is correct
2 Correct 14 ms 1520 KB Output is correct
3 Correct 11 ms 1496 KB Output is correct
4 Correct 9 ms 1456 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 6 ms 1404 KB Output is correct
7 Correct 9 ms 1552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2772 KB Output is correct
2 Correct 20 ms 2772 KB Output is correct
3 Correct 38 ms 5320 KB Output is correct
4 Correct 23 ms 4864 KB Output is correct
5 Correct 11 ms 2860 KB Output is correct
6 Correct 30 ms 4688 KB Output is correct
7 Correct 27 ms 5584 KB Output is correct
8 Correct 23 ms 2744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 48 ms 5316 KB Output is correct
28 Correct 59 ms 5304 KB Output is correct
29 Correct 58 ms 5316 KB Output is correct
30 Correct 59 ms 5352 KB Output is correct
31 Correct 23 ms 4920 KB Output is correct
32 Correct 11 ms 1536 KB Output is correct
33 Correct 14 ms 1520 KB Output is correct
34 Correct 11 ms 1496 KB Output is correct
35 Correct 9 ms 1456 KB Output is correct
36 Correct 0 ms 320 KB Output is correct
37 Correct 6 ms 1404 KB Output is correct
38 Correct 9 ms 1552 KB Output is correct
39 Correct 27 ms 2772 KB Output is correct
40 Correct 20 ms 2772 KB Output is correct
41 Correct 38 ms 5320 KB Output is correct
42 Correct 23 ms 4864 KB Output is correct
43 Correct 11 ms 2860 KB Output is correct
44 Correct 30 ms 4688 KB Output is correct
45 Correct 27 ms 5584 KB Output is correct
46 Correct 23 ms 2744 KB Output is correct
47 Correct 24 ms 2748 KB Output is correct
48 Correct 30 ms 2816 KB Output is correct
49 Correct 49 ms 5304 KB Output is correct
50 Correct 27 ms 4932 KB Output is correct
51 Correct 21 ms 4664 KB Output is correct
52 Correct 24 ms 5300 KB Output is correct
53 Correct 21 ms 4912 KB Output is correct
54 Correct 38 ms 5852 KB Output is correct
55 Correct 42 ms 5356 KB Output is correct