CSES - Labyrinth
Authors: Nathan Wang, Sofia Yang, David Zhou
Video Solution
By David Zhou
Video Solution Code
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;#define ii pair<int, int>#define f first#define s second#define mp make_pairint n, m;
Java
import java.io.*;import java.util.*;public class cses1193 {public static int[] dX = {-1, 0, 0, 1};public static int[] dY = {0, -1, 1, 0};public static String dirs = "ULRD";// Coordinates for points A and B.public static point A = new point(-1, -1);
Python
from collections import dequeMAX_N = 1000STEP_DIR = "URDL"# 0 = up, 1 = right, 2 = down, 3 = leftDX = [-1, 0, 1, 0]DY = [0, 1, 0, -1]vis = [[False for _ in range(MAX_N)] for _ in range(MAX_N)]
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!