Submission #722581

#TimeUsernameProblemLanguageResultExecution timeMemory
722581yeysoRainforest Jumps (APIO21_jumps)C++14
Compilation error
0 ms0 KiB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#include <vector>
vector<vector<int>> adj(n, vector<int>());
void init(int n, vector<int> h) {
    // adjancency matrix
    
    for(int i = 0; i < n; i ++){
        // jumps to the right
        for(int j = i + 1; j < n; j ++){
            if(h[j] > h[i]){
                adj[i].push_back(j);
                break;
            }
        }
        // jumps to the left
        for(int j = i - 1; j >= 0; j --){
            if(h[j] > h[i]){
                adj[i].push_back(j);
                break;
            }
        }
    }
}

int minimum_jumps(int a, int b, int c, int d) {
  // DISTANCE THEN NODE
    queue<pair<int, int>> q;
    for(int i = a; i <= b; i ++){
        q.push({0, i});
    }
    vector<int> v(n, 0);
    int node = 0; int dist = 0;
    int res = -1;
    while(!q.empty()){
        node = q.front().second;
        dist = q.front().first;
        q.pop();
        if(!v[node]){
            v[node] = 1;
            for(int i = 0; i < adj[node].size(); i ++){
                q.push({dist+1, adj[node][i]});
            }
            if(c <= node and node <= d){
                res = dist;
                //cout << node << " ";
            }
        }
    }
    return res;
}

Compilation message (stderr)

jumps.cpp:5:25: error: 'n' was not declared in this scope; did you mean 'yn'?
    5 | vector<vector<int>> adj(n, vector<int>());
      |                         ^
      |                         yn
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:33:19: error: 'n' was not declared in this scope
   33 |     vector<int> v(n, 0);
      |                   ^
jumps.cpp:42:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int i = 0; i < adj[node].size(); i ++){
      |                            ~~^~~~~~~~~~~~~~~~~~