답안 #1085565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085565 2024-09-08T12:25:35 Z vjudge1 Global Warming (CEOI18_glo) C++17
10 / 100
113 ms 4660 KB
#include <bits/stdc++.h>

using namespace std;
long long n,k;
long long niza[200001];
long long dp[200001][2];
long long odg0,odg1;

long long najdi0(long long l,long long r,long long traze)
{
    if (l>=r)
    {
        if (dp[r][0]<traze) return r;
        else return 0;
    }
    long long mid = (l+r)/2;
    if (traze>dp[mid][0]) return max(mid,najdi0(mid+1,r,traze));
    else return najdi0(l,mid,traze);
}
long long najdi1(long long l,long long r,long long traze)
{
    if (l>=r)
    {
        if (dp[r][1]<traze) return r;
        else return 0;
    }
    long long mid = (l+r)/2;
    if (traze>dp[mid][1]) return max(mid,najdi1(mid+1,r,traze));
    else return najdi1(l,mid,traze);
}

int main()
{
    cin>>n>>k;
    for (long long i=1;i<=n;i++) cin>>niza[i];

    for (long long i=1;i<=n;i++)
    {
        long long d0=0,d1=0;

        d0 = max(d0,najdi0(1,odg0,niza[i]-k)+1);

        d1 = max(d1,najdi0(1,odg0,niza[i])+1);
        d1 = max(d1,najdi1(1,odg1,niza[i])+1);

        if (odg0<d0) {
            odg0 = d0;
            dp[d0][0] = niza[i]-k;
        }
        if (odg1<d1){
            odg1 = d1;
            dp[d1][1] = niza[i];
        }
        dp[d0][0] = min(dp[d0][0],niza[i]-k);
        dp[d1][1] = min(dp[d1][1],niza[i]);
    }

    cout<<max(odg0,odg1)<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 3880 KB Output is correct
2 Correct 76 ms 3924 KB Output is correct
3 Correct 73 ms 3908 KB Output is correct
4 Correct 113 ms 4020 KB Output is correct
5 Correct 53 ms 4660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1112 KB Output is correct
2 Correct 25 ms 1116 KB Output is correct
3 Correct 27 ms 1116 KB Output is correct
4 Correct 13 ms 1324 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 2164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -