CF - Magic Ship
Author: Kevin Sheng
C++
#include <cmath>#include <iostream>#include <string>#include <vector>using std::cin;using std::cout;using std::endl;bool reachable(std::pair<long long, long long> start,
Java
import java.io.*;import java.util.Arrays;public class MagicShip {public static void main(String[] args) throws IOException {BufferedReader read =new BufferedReader(new InputStreamReader(System.in));long[] atPos = Arrays.stream(read.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
Python
from typing import Listdef reachable(start: List[int], end: List[int], wind: str, time: int) -> bool:start = start.copy()# count the net changes after one wind cyclewind_x = wind.count("R") - wind.count("L")wind_y = wind.count("U") - wind.count("D")cycle_num = time // len(wind)# speed this up by multiplying by the amount of complete cycles in the time
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!