답안 #1085680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085680 2024-09-08T15:00:01 Z vjudge1 Global Warming (CEOI18_glo) C++17
100 / 100
195 ms 16464 KB
#include <bits/stdc++.h>

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

long long traze;
long long najdi(long long l,long long r,long long poz,long long koj)
{
    //cout<<"l="<<l<<" r="<<r<<" traze="<<traze<<" koj="<<koj<<" gleda "<<dp[poz][koj]<<endl;
    if (traze<=dp[poz][koj]) return 0;
    if (l==r) return r;

    long long mid = (l+r)/2;
    long long op = najdi(mid+1,r,poz*2+1,koj);

    if (op>0) return op;
    return najdi(l,mid,poz*2,koj);
}
long long p;
long long dodaj(long long l,long long r,long long poz,long long koj)
{
    if (l>p || r<p) return dp[poz][koj];
    if (l==r) {
        dp[poz][koj] = min(traze,dp[poz][koj]);
        //cout<< "dp["<<poz<<"]["<<koj<<"] = "<<dp[poz][koj]<<endl;
        return dp[poz][koj];
    }

    long long mid = (l+r)/2;
    dp[poz][koj] = min(dodaj(l,mid,poz*2,koj),dodaj(mid+1,r,poz*2+1,koj));
    //cout<< "dp["<<poz<<"]["<<koj<<"] = "<<dp[poz][koj]<<endl;
    return dp[poz][koj];
}


int main()
{
    cin>>n>>k;
    for (long long i=1;i<=n;i++) cin>>niza[i];
    for (long long i=0;i<=n*4;i++){
        dp[i][0]=1000000000000;
        dp[i][1]=1000000000000;
    }

    long long odg = 0;
    for (long long i=1;i<=n;i++)
    {
        traze = niza[i]-k;
        long long op1 = najdi(1,n,1,0)+1;
        traze = niza[i];
        long long op2 = najdi(1,n,1,0)+1;
        long long op3 = najdi(1,n,1,1)+1;

        traze = niza[i]-k;
        p = op1;
        dodaj(1,n,1,0);
        traze = niza[i];
        p = op2;
        dodaj(1,n,1,1);
        traze = niza[i];
        p = op3;
        dodaj(1,n,1,1);

        odg = max(odg,op1);
        odg = max(odg,op2);
        odg = max(odg,op3);

        //cout<< "za "<<niza[i]<< " op1="<<op1<<" op2=" <<op2<<" op3="<<op3<<endl<<endl;
    }

    cout<<odg<<endl;
    return 0;
}
/*
8 100
7 3 5 12 2 7 3 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 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 1 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 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 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 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 448 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 448 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 16208 KB Output is correct
2 Correct 176 ms 16340 KB Output is correct
3 Correct 173 ms 16420 KB Output is correct
4 Correct 165 ms 16212 KB Output is correct
5 Correct 134 ms 15440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 4188 KB Output is correct
2 Correct 40 ms 4440 KB Output is correct
3 Correct 44 ms 4456 KB Output is correct
4 Correct 31 ms 4188 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 30 ms 4224 KB Output is correct
7 Correct 34 ms 4348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 8284 KB Output is correct
2 Correct 77 ms 8428 KB Output is correct
3 Correct 164 ms 16212 KB Output is correct
4 Correct 137 ms 15444 KB Output is correct
5 Correct 66 ms 8024 KB Output is correct
6 Correct 121 ms 14928 KB Output is correct
7 Correct 146 ms 15660 KB Output is correct
8 Correct 86 ms 8272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 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 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 448 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 448 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 195 ms 16208 KB Output is correct
28 Correct 176 ms 16340 KB Output is correct
29 Correct 173 ms 16420 KB Output is correct
30 Correct 165 ms 16212 KB Output is correct
31 Correct 134 ms 15440 KB Output is correct
32 Correct 38 ms 4188 KB Output is correct
33 Correct 40 ms 4440 KB Output is correct
34 Correct 44 ms 4456 KB Output is correct
35 Correct 31 ms 4188 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 30 ms 4224 KB Output is correct
38 Correct 34 ms 4348 KB Output is correct
39 Correct 79 ms 8284 KB Output is correct
40 Correct 77 ms 8428 KB Output is correct
41 Correct 164 ms 16212 KB Output is correct
42 Correct 137 ms 15444 KB Output is correct
43 Correct 66 ms 8024 KB Output is correct
44 Correct 121 ms 14928 KB Output is correct
45 Correct 146 ms 15660 KB Output is correct
46 Correct 86 ms 8272 KB Output is correct
47 Correct 75 ms 8272 KB Output is correct
48 Correct 78 ms 8276 KB Output is correct
49 Correct 184 ms 16204 KB Output is correct
50 Correct 149 ms 15440 KB Output is correct
51 Correct 109 ms 11608 KB Output is correct
52 Correct 131 ms 15552 KB Output is correct
53 Correct 126 ms 15624 KB Output is correct
54 Correct 184 ms 16212 KB Output is correct
55 Correct 145 ms 16464 KB Output is correct