답안 #844674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844674 2023-09-05T16:34:15 Z amine_aroua Global Warming (CEOI18_glo) C++17
100 / 100
52 ms 8796 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(int i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;

ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (gcd)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (lcm)

// HERE IS THE SOLUTION
int n  , x;
signed main()
{
    boost;
    cin.tie(0);
    cout.tie(0);
//    freopen("io.txt" , "r" , stdin);
    cin>>n>>x;
    vi v(n);
    fore(i , n)
    {
        cin>>v[i];
    }
    vi dpA(n , INT_MAX);
    vi pref(n);
    fore(i , n)
    {
        int cur = v[i];
        int idx = lower_bound(all(dpA) , cur) - dpA.begin();
        dpA[idx] = cur;
        pref[i] = idx + 1;
    }
    int ans = pref[n - 1];
    vi dpB(n , INT_MAX);
    forn(i , n - 1 , 0)
    {
        int cur = v[i];
        int idx = lower_bound(all(dpB) , -cur + x) - dpB.begin();
        ans = max(ans , idx + pref[i]);
        int pos = lower_bound(all(dpB) , -cur) - dpB.begin();
        dpB[pos] = -cur;
    }
    cout<<ans<<nl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 6952 KB Output is correct
2 Correct 48 ms 6708 KB Output is correct
3 Correct 52 ms 6692 KB Output is correct
4 Correct 48 ms 6712 KB Output is correct
5 Correct 34 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1884 KB Output is correct
2 Correct 11 ms 1884 KB Output is correct
3 Correct 11 ms 2140 KB Output is correct
4 Correct 10 ms 2036 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 1872 KB Output is correct
7 Correct 9 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 3420 KB Output is correct
2 Correct 20 ms 3420 KB Output is correct
3 Correct 42 ms 6708 KB Output is correct
4 Correct 34 ms 6484 KB Output is correct
5 Correct 18 ms 3420 KB Output is correct
6 Correct 28 ms 6308 KB Output is correct
7 Correct 31 ms 6236 KB Output is correct
8 Correct 17 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 452 KB Output is correct
27 Correct 49 ms 6952 KB Output is correct
28 Correct 48 ms 6708 KB Output is correct
29 Correct 52 ms 6692 KB Output is correct
30 Correct 48 ms 6712 KB Output is correct
31 Correct 34 ms 6904 KB Output is correct
32 Correct 11 ms 1884 KB Output is correct
33 Correct 11 ms 1884 KB Output is correct
34 Correct 11 ms 2140 KB Output is correct
35 Correct 10 ms 2036 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 9 ms 1872 KB Output is correct
38 Correct 9 ms 1884 KB Output is correct
39 Correct 21 ms 3420 KB Output is correct
40 Correct 20 ms 3420 KB Output is correct
41 Correct 42 ms 6708 KB Output is correct
42 Correct 34 ms 6484 KB Output is correct
43 Correct 18 ms 3420 KB Output is correct
44 Correct 28 ms 6308 KB Output is correct
45 Correct 31 ms 6236 KB Output is correct
46 Correct 17 ms 3584 KB Output is correct
47 Correct 26 ms 4432 KB Output is correct
48 Correct 24 ms 4444 KB Output is correct
49 Correct 49 ms 8796 KB Output is correct
50 Correct 36 ms 7772 KB Output is correct
51 Correct 29 ms 5980 KB Output is correct
52 Correct 36 ms 7756 KB Output is correct
53 Correct 33 ms 8020 KB Output is correct
54 Correct 33 ms 8540 KB Output is correct
55 Correct 39 ms 8636 KB Output is correct