답안 #393690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393690 2021-04-24T09:17:52 Z Qw3rTy Rabbit Carrot (LMIO19_triusis) C++11
0 / 100
1 ms 332 KB
#include <iostream>
using namespace std;

const int maxN = 2e5+5;

int a[maxN];
int f[maxN];
int dif[maxN];
int ps[maxN];
int N,M;

void testIO(){
    freopen("../test.in","r",stdin);
    return;
    return;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //testIO();
    cin >> N >> M;
    for(int i = 1; i <= N; ++i)cin >> a[i];
    int curHeight = M; //current height that can be reached
    int prevHeight = M; //maximum height that can be reached
    for(int i = 1; i <= N; ++i){
        //Can jump onto the next pole
        if(a[i] <= curHeight){
            dif[i] = 0;
            //Moves forward
            prevHeight = curHeight;
            curHeight = a[i] + M;
        }
        else{
            dif[i] = 1;
            curHeight = max(prevHeight, curHeight); //Tries to go as high as possible
        }
    }
    for(int i = 1; i <= N; ++i)ps[i] = ps[i-1] + dif[i];
    for(int i = 1; i <= N; ++i){
        for(int j = 1; j < i; ++j){
            if(a[j] + M < a[i]){
                f[i] = max(f[i],f[j] + ps[i] - ps[j-1]);
            }
        }
    }
    int res = 0;
    for(int i = 1; i <= N; ++i)res = max(res,f[i]);
    cout << res << '\n';
    return 0;
}

Compilation message

triusis.cpp: In function 'void testIO()':
triusis.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -