답안 #393693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393693 2021-04-24T09:31:08 Z Qw3rTy Rabbit Carrot (LMIO19_triusis) C++11
0 / 100
1 ms 332 KB
#include <iostream>
#include <cstring>
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; //maximum previous height that can be reached
    int prevHeight = M; //maximum current 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;
            prevHeight = curHeight;
            curHeight = max(prevHeight, curHeight) + M; //Try 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 = 0; 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:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -