제출 #439024

#제출 시각아이디문제언어결과실행 시간메모리
439024aris12345678밀림 점프 (APIO21_jumps)C++14
4 / 100
1244 ms2624 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 200005;
bool sub1 = false;
vector<int> height;

void init(int n, vector<int> h) {
    if(is_sorted(h.begin(), h.end()))
        sub1 = true;
    height = h;
}

int bfs(int i, int end) {
    int n = int(height.size());
    queue<pair<int, int> > q;
    q.push({i, 0});
    while(!q.empty()) {
        int u = q.front().first, jumps = q.front().second;
        q.pop();
        if(u == end)
            return jumps;
        if(height[u] > height[end]) continue;
        int j = u;
        while(j >= 0 && height[j] <= height[u])
            j--;
        // cout << "bfs_1: " << u << " " << j << " " << jumps+1 << "\n";
        if(j >= 0)
            q.push({j, jumps+1});
        j = u;
        while(j < n && height[j] <= height[u])
            j++;
        // cout << "bfs_2: " << u << " " << j << " " << jumps+1 << "\n";
        if(j < n)
            q.push({j, jumps+1});
    }
    return -1;
}

int minimum_jumps(int a, int b, int c, int d) {
    if(sub1)
        return c-b;
    else {
        int ans = INT_MAX;
        for(int i = a; i <= b; i++) {
            int pos = i;
            for(int j = c; j <= d; j++) {
                if(height[j] < height[i]) continue;
                int jumps = bfs(pos, j);
                // cout << i << " " << j << " " << jumps << "\n";
                if(jumps != -1)
                    ans = min(ans, jumps);
            }
        }
        return ans;
    }
}

/*
int main() {
    int n = 7;
    vector<int> h = {3, 2, 1, 6, 4, 5, 7};
    init(n, h);
    int a = 1, b = 3, c = 5, d = 6;
    printf("%d\n", minimum_jumps(a, b, c, d));
    return 0;
}*/

/*
0 1 2 3 4 5 6
3 2 1 6 4 5 7

(1, 3)
(5, 6)
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...