답안 #994818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994818 2024-06-08T06:46:47 Z debargha Global Warming (CEOI18_glo) C++14
100 / 100
40 ms 5496 KB
//JAI SHREE RAM
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e18
#define MAXN 1123456
#define MOD 1000000007
/*
-----------------------------ordered set--------------------
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
#include <iostream>  
using namespace __gnu_pbds;  
using namespace std;  

typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
*/  
/*-----------------PRIME FACTOR-------------
for (int i = 2; i*i <= n; i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            printf("%d ", i);
            n = n/i;
        }
    }
*/
/*-----------------------sieve----------------
vector<bool> prime(MAXN, false);
vector<bool> used(MAXN, false);
void precalc() {
    for (int i = 2; i < MAXN; ++i) {
        if (!   used[i]) {
            prime[i] = true;
            for (int j = i; j < MAXN; j += i) {
                used[j] = true;
            }
        }
    }
}*/
/*--------------------------------sqrt function------------------------
ll my_sqrt(ll a)
{
    ll l=0,r=5000000001;
    while(r-l>1)
    {
        ll mid=(l+r)/2;
        if(1ll*mid*mid<=a)l=mid;
        else r=mid;
    }
    return l;
}
int getclosest(int x)
{
    int n = sqrt(x);
    if(n*n==x)
    {
        return 0;
    }
    else
    {
        return (n+1)*(n+1) - x;
    }
}

const int N = 40004;
const int M = 502;
int dp[N][M];

int reverse(int n) {
    int r = 0;
    while (n > 0) {
        r = r * 10 + n % 10;
        n = n / 10;
    }
    return r;
}

int palindrome(int i) {
    return reverse(i) == i;
}

void precompute_palindromes(vector<int>& palin) {
    palin.push_back(0);
    for (int i = 1; i < 2 * N; i++) {
        if (palindrome(i)) {
            palin.push_back(i);
        }
    }
}
*/
void solve() 
{
    int x,n;
    cin>>n>>x;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    vector<int>dp(n,INT_MAX);
    vector<int>pref(n);
    int len = 0;
    for(int i=0;i<n;i++)
    {
        int j = lower_bound(dp.begin(),dp.end(),v[i])-dp.begin();
        dp[j] = v[i];
        pref[i] = j+1;
        len = max(len,pref[i]);
    }
    dp = vector<int>(n,INT_MAX);
    for(int i=n-1;i>=0;i--)
    {
        int pos = lower_bound(dp.begin(),dp.end(),-v[i]+x)-dp.begin();
        len = max(len,pref[i]+pos);
        int insert = lower_bound(dp.begin(),dp.end(),-v[i])-dp.begin();
        dp[insert] = -v[i];
    }
    cout<<len<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t=1;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 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 424 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 456 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 424 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 456 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 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 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 424 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 456 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 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 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 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5312 KB Output is correct
2 Correct 38 ms 5460 KB Output is correct
3 Correct 38 ms 5496 KB Output is correct
4 Correct 38 ms 5468 KB Output is correct
5 Correct 27 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1628 KB Output is correct
2 Correct 10 ms 1628 KB Output is correct
3 Correct 9 ms 1628 KB Output is correct
4 Correct 7 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1340 KB Output is correct
7 Correct 8 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2764 KB Output is correct
2 Correct 18 ms 2908 KB Output is correct
3 Correct 36 ms 5332 KB Output is correct
4 Correct 27 ms 4692 KB Output is correct
5 Correct 14 ms 2396 KB Output is correct
6 Correct 25 ms 4444 KB Output is correct
7 Correct 28 ms 5120 KB Output is correct
8 Correct 15 ms 2768 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 424 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 456 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 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 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 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 40 ms 5312 KB Output is correct
28 Correct 38 ms 5460 KB Output is correct
29 Correct 38 ms 5496 KB Output is correct
30 Correct 38 ms 5468 KB Output is correct
31 Correct 27 ms 4688 KB Output is correct
32 Correct 9 ms 1628 KB Output is correct
33 Correct 10 ms 1628 KB Output is correct
34 Correct 9 ms 1628 KB Output is correct
35 Correct 7 ms 1372 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 7 ms 1340 KB Output is correct
38 Correct 8 ms 1628 KB Output is correct
39 Correct 18 ms 2764 KB Output is correct
40 Correct 18 ms 2908 KB Output is correct
41 Correct 36 ms 5332 KB Output is correct
42 Correct 27 ms 4692 KB Output is correct
43 Correct 14 ms 2396 KB Output is correct
44 Correct 25 ms 4444 KB Output is correct
45 Correct 28 ms 5120 KB Output is correct
46 Correct 15 ms 2768 KB Output is correct
47 Correct 19 ms 2908 KB Output is correct
48 Correct 21 ms 2868 KB Output is correct
49 Correct 38 ms 5328 KB Output is correct
50 Correct 30 ms 4548 KB Output is correct
51 Correct 28 ms 3672 KB Output is correct
52 Correct 29 ms 4696 KB Output is correct
53 Correct 26 ms 4692 KB Output is correct
54 Correct 29 ms 5456 KB Output is correct
55 Correct 31 ms 5456 KB Output is correct