Submission #672061

# Submission time Handle Problem Language Result Execution time Memory
672061 2022-12-14T16:48:55 Z Vahe Rainforest Jumps (APIO21_jumps) C++17
Compilation error
0 ms 0 KB
#include "jumps.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int n, a, b, c, d;;
vector<int> h, pge, nge, dp;
vector<vector<int>> gp;
 
vector<int> pge_(vector<int> v)
{
    vector<int> tmp(v.size());
    stack<int> s;
    s.push(0);
    tmp[0] = -1;
    for (int i = 1; i < v.size(); i++)
    {
        while (!s.empty() && v[s.top()] < v[i]) s.pop();
        tmp[i] = (s.empty() ? -1 : s.top());
        s.push(i);
    }
    return tmp;
}
vector<int> nge_(vector<int> v)
{
    stack<int> s;
    vector<int> tmp(v.size(), -1);
    for (int i = 0; i < n; i++)
    {
        while (!s.empty() && v[s.top()] < v[i]) tmp[s.top()] = i, s.pop();
        s.push(i);
    }
    return tmp;
}
 
void dfs(int u)
{
    if (u >= c && u <= d) { dp[u] = 0; return; }
    if (dp[u] != 2e9) return;
 
    if (gp[u].size() > 0) dfs(gp[u][0]);
    if (gp[u].size() > 1) dfs(gp[u][1]);
 
    int x = (gp[u].size() > 0 ? dp[gp[u][0]] : 2e9);
    int y = (gp[u].size() > 1 ? dp[gp[u][1]] : 2e9);
    dp[u] = min(x, y) + 1;
}
 
void init(int N, vector<int> H)
{
    n = N;
    h = H;
    pge = pge_(H);
    nge = nge_(H);
    gp = vector<vector<int>>#include "jumps.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int n, a, b, c, d;;
vector<int> h, pge, nge, dp;
vector<vector<int>> gp;
bool arajitest = 1;
 
vector<int> pge_(vector<int> v)
{
    vector<int> tmp(v.size());
    stack<int> s;
    s.push(0);
    tmp[0] = -1;
    for (int i = 1; i < v.size(); i++)
    {
        while (!s.empty() && v[s.top()] < v[i]) s.pop();
        tmp[i] = (s.empty() ? -1 : s.top());
        s.push(i);
    }
    return tmp;
}
vector<int> nge_(vector<int> v)
{
    stack<int> s;
    vector<int> tmp(v.size(), -1);
    for (int i = 0; i < n; i++)
    {
        while (!s.empty() && v[s.top()] < v[i]) tmp[s.top()] = i, s.pop();
        s.push(i);
    }
    return tmp;
}
 
void dfs(int u)
{
    if (u >= c && u <= d) { dp[u] = 0; return; }
    if (dp[u] != 2e9) return;
 
    if (gp[u].size() > 0) dfs(gp[u][0]);
    if (gp[u].size() > 1) dfs(gp[u][1]);
 
    int x = (gp[u].size() > 0 ? dp[gp[u][0]] : 2e9);
    int y = (gp[u].size() > 1 ? dp[gp[u][1]] : 2e9);
    dp[u] = min(x, y) + 1;
}
 
void init(int N, vector<int> H)
{
    n = N;
    h = H;
    pge = pge_(H);
    nge = nge_(H);
    gp = vector<vector<int>>(n);
    for (int i = 0; i < n; i++)
    {
        if (pge[i] != -1) gp[i].push_back(pge[i]b);
        if (nge[i] != -1) gp[i].push_back(nge[i]);
    }
  	for(int i = 0; i < n; i++) if(H[i] != i + 1) arajitest = 1;
}
 
int minimum_jumps(int A, int B, int C, int D)
{
    a = A, b = B, c = C, d = D;
  	if(arajitest) return C - B;
    dp = vector<int>(n, 2e9);
    int mn = 2e9;
    for (int i = a; i <= b; i++) dfs(i), mn = min(mn, dp[i]);
    return (mn >= 2e9 ? -1 : mn);
}(n);
    for (int i = 0; i < n; i++)
    {
        if (pge[i] != -1) gp[i].push_back(pge[i]);
        if (nge[i] != -1) gp[i].push_back(nge[i]);
    }
}
 
int minimum_jumps(int A, int B, int C, int D)
{
    a = A, b = B, c = C, d = D;
    dp = vector<int>(n, 2e9);
    int mn = 2e9;
    for (int i = a; i <= b; i++) dfs(i), mn = min(mn, dp[i]);
    return (mn >= 2e9 ? -1 : mn);
}

Compilation message

jumps.cpp:56:29: error: stray '#' in program
   56 |     gp = vector<vector<int>>#include "jumps.h"
      |                             ^
jumps.cpp: In function 'std::vector<int> pge_(std::vector<int>)':
jumps.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 1; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:56:30: error: expected primary-expression before 'include'
   56 |     gp = vector<vector<int>>#include "jumps.h"
      |                              ^~~~~~~
jumps.cpp:68:1: error: a function-definition is not allowed here before '{' token
   68 | {
      | ^
jumps.cpp:82:1: error: a function-definition is not allowed here before '{' token
   82 | {
      | ^
jumps.cpp:94:1: error: a function-definition is not allowed here before '{' token
   94 | {
      | ^
jumps.cpp:107:1: error: a function-definition is not allowed here before '{' token
  107 | {
      | ^
jumps.cpp:122:1: error: a function-definition is not allowed here before '{' token
  122 | {
      | ^
jumps.cpp:129:3: warning: statement has no effect [-Wunused-value]
  129 | }(n);
      |  ~^~
jumps.cpp:62:8: warning: unused variable 'a' [-Wunused-variable]
   62 | int n, a, b, c, d;;
      |        ^
jumps.cpp:62:11: warning: unused variable 'b' [-Wunused-variable]
   62 | int n, a, b, c, d;;
      |           ^
jumps.cpp:62:14: warning: unused variable 'c' [-Wunused-variable]
   62 | int n, a, b, c, d;;
      |              ^
jumps.cpp:62:17: warning: unused variable 'd' [-Wunused-variable]
   62 | int n, a, b, c, d;;
      |                 ^
jumps.cpp:65:6: warning: unused variable 'arajitest' [-Wunused-variable]
   65 | bool arajitest = 1;
      |      ^~~~~~~~~