답안 #261758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261758 2020-08-12T04:25:31 Z cheeheng Climbers (RMI18_climbers) C++14
5 / 100
421 ms 399508 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;

int h[5005];
int h3[5005];

int h2[250005];

short dist[10005][10005];

int main(){
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N; i ++){
        scanf("%d", &h[i]);
    }


    int P = 2;
    h3[0] = h[0];
    h3[1] = h[1];
    for(int i = 2; i < N; i ++){
        if(h3[i-2] >= h3[i-1] && h3[i-1] >= h3[i]){

        }
    }

    int M = 1;
    h2[0] = 0;
    for(int i = 0; i < N-1; i ++){
        if(h[i] < h[i+1]){
            for(int j = h[i]+1; j <= h[i+1]; j ++){
                h2[M++] = j;
            }
        }else if(h[i] > h[i+1]){
            for(int j = h[i]-1; j >= h[i+1]; j --){
                h2[M++] = j;
            }
        }
    }

    /*
    for(int i = 0; i < M; i ++){
        printf("%d ", h2[i]);
    }
    printf("\n");
    */

    for(int i = 0; i < M; i ++){
        //printf("h2[%d]=%d\n", i, h2[i]);
    }

    long long ans = 0;
    int A = 0;
    int B = M-1;
    memset(dist, -1, sizeof(dist));
    dist[A][B] = 0;
    queue<ii> q;
    q.push(ii(A, B));
    while(!q.empty()){
        int A, B;
        tie(A, B) = q.front(); q.pop();
        if(A == B){
            printf("%d\n", dist[A][B]);
            return 0;
        }
        //printf("while loop: %d %d %d\n", A, B, dist[A][B]);
        //printf("%d %d %d %d\n", h2[A+1], h2[A-1], h2[B+1], h2[B-1]);
        //if(ans > 100){break;}
        if(h2[A+1] == h2[B-1]){
            if(dist[A+1][B-1] == -1){
                dist[A+1][B-1] = dist[A][B]+1;
                q.push(ii(A+1, B-1));
            }
        }

        if(h2[A-1] == h2[B-1]){
            if(dist[A-1][B-1] == -1){
                dist[A-1][B-1] = dist[A][B]+1;
                q.push(ii(A-1, B-1));
            }
        }
        if(h2[A+1] == h2[B+1]){
            if(dist[A+1][B+1] == -1){
                dist[A+1][B+1] = dist[A][B]+1;
                q.push(ii(A+1, B+1));
            }
        }

    }
    throw;

    ans = 1LL << 61;
    for(int i = 0; i < M; i ++){
        if(dist[i][i] == -1){continue;}
        ans = min(ans, (long long)dist[i][i]);
    }

    if(ans == (1LL << 61)){
        printf("NO");
        return 0;
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

climbers.cpp: In function 'int main()':
climbers.cpp:22:9: warning: unused variable 'P' [-Wunused-variable]
     int P = 2;
         ^
climbers.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
climbers.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &h[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 421 ms 397636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 411 ms 399260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 12 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 364 ms 399396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 12 ms 2688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 196304 KB Output is correct
2 Runtime error 362 ms 397304 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 375 ms 397560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 360 ms 397432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 363 ms 397432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 369 ms 399508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 11 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 12 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 12 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 16 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 12 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 12 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 13 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 12 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 12 ms 2560 KB Execution killed with signal 11 (could be triggered by violating memory limits)