Submission #553762

# Submission time Handle Problem Language Result Execution time Memory
553762 2022-04-26T20:51:42 Z Zhora_004 Rainforest Jumps (APIO21_jumps) C++17
Compilation error
0 ms 0 KB
#include "jumps.h"
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
#include <fstream>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
/*ofstream fout("timeline.out");
ifstream fin("timeline.in");*/
using ll = long long;
using namespace std;
int n, a, b, c, d, ans;
vector<int> h, dp, nge, pge;

bool task(int id)
{
	if (id == 1)
	{
		for (int i = 0; i < n; i++) if (h[i] != i + 1) return 0;
		return 1;
	}
	else if (id == 3)
	{
		return max(n, q) <= 2000;
	}
	else if (id == 4)
	{
		return q <= 5;
	}
	return 0;
}

void NGE()
{
    stack<int> s;
    s.push(0);
    for (int i = 1; i < n; i++)
    {
        if (s.empty())
        {
            s.push(i);
            continue;
        }
        while (!s.empty() && h[s.top()] < h[i])
        {
            nge[s.top()] = i;
            s.pop();
        }
        s.push(i);
    }
    while (!s.empty())
    {
        nge[s.top()] = -1;
        s.pop();
    }
}

void PGE()
{
    stack<int> s;
    s.push(0);
    pge[0] = -1;
    for (int i = 1; i < n; i++)
    {
        while (!s.empty() && h[s.top()] < h[i]) s.pop();
        if (s.empty()) pge[i] = -1;
        else pge[i] = s.top();
        s.push(i);
    }
}

int dfs(int u)
{
    if (dp[u] != inf + 1) return dp[u];
    if (c <= u && u <= d) return dp[u] = 0;
    int r = nge[u];
    int ans = inf;
    if (r != -1) ans = min(ans, dfs(r) + 1);
    int l = pge[u];
    if (l != -1) ans = min(ans, dfs(l) + 1);
    return dp[u] = ans;
}

void init(int N, std::vector<int> H) {
	n = N;
	h = H;
	nge = pge = vector<int>(n);
	NGE();
	PGE();
}


int minimum_jumps(int A, int B, int C, int D) {
	a = A, b = B, c = C, d = D;
	if (task(1)) return c - b;
	else if (task(3) || task(4))
	{
        dp = vector<int>(n, inf + 1);
        ans = inf;
        for (int i = a; i <= b; i++) ans = min(ans, dfs(i));
        if (ans == inf) ans = -1;
        return ans;
	}
}

Compilation message

jumps.cpp: In function 'bool task(int)':
jumps.cpp:48:17: error: 'q' was not declared in this scope
   48 |   return max(n, q) <= 2000;
      |                 ^
jumps.cpp:52:10: error: 'q' was not declared in this scope
   52 |   return q <= 5;
      |          ^
jumps.cpp: In function 'int dfs(int)':
jumps.cpp:98:18: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   98 |     if (dp[u] != inf + 1) return dp[u];
      |                  ^~~
      |                  ynf
jumps.cpp:101:15: error: 'inf' was not declared in this scope; did you mean 'ynf'?
  101 |     int ans = inf;
      |               ^~~
      |               ynf
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:122:29: error: 'inf' was not declared in this scope; did you mean 'ynf'?
  122 |         dp = vector<int>(n, inf + 1);
      |                             ^~~
      |                             ynf
jumps.cpp:128:1: warning: control reaches end of non-void function [-Wreturn-type]
  128 | }
      | ^