답안 #117072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117072 2019-06-14T15:31:54 Z emilem 게임판 (CEOI13_board) Java 11
10 / 100
200 ms 186460 KB
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

class board
{
    static BigInteger min(BigInteger a, BigInteger b)
    {
        return a.compareTo(b) < 0 ? a : b;
    }
	static int Depth(String a)
	{
		int depth = 0;
		for (int i = 0; i < a.length(); ++i)
			if (a.charAt(i) == 'U')
				--depth;
			else if (a.charAt(i) == '1' || a.charAt(i) == '2')
				++depth;
		return depth;
	}
	static BigInteger Coord(String a)
	{
		BigInteger coord = BigInteger.ZERO;
		for (int i = 0; i < a.length(); ++i)
			switch(a.charAt(i))
			{
			case '1':
				coord = coord.multiply(BigInteger.valueOf(2)); break;
			case '2':
				coord = coord.multiply(BigInteger.valueOf(2));
				coord = coord.add(BigInteger.ONE); break;
			case 'L':
				coord = coord.subtract(BigInteger.ONE); break;
			case 'R':
				coord = coord.add(BigInteger.ONE); break;
			case 'U':
				coord = coord.divide(BigInteger.valueOf(2));
			}
		return coord;
	}
    public static void main(String[] args)
	{
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
		String path = in.nextString();
		int aDepth = Depth(path);
		BigInteger aCoord = Coord(path);
		path = in.nextString();
		int bDepth = Depth(path);
		BigInteger bCoord = Coord(path);
		int iii = bCoord.intValue();
		if (aDepth > bDepth)
		{
		    int temp1;
			temp1 = aDepth; aDepth = bDepth; bDepth = temp1;
			BigInteger temp2;
			temp2 = aCoord; aCoord = bCoord; bCoord = temp2;
		}
		int depthSteps = bDepth - aDepth;
		bDepth = aDepth;
		bCoord = bCoord.shiftLeft(-depthSteps);
		BigInteger ans = aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps));
		while (aDepth-- > 0)
		{
			--aDepth;
			depthSteps += 2;
			aCoord = aCoord.divide(BigInteger.valueOf(2));
			bCoord = bCoord.divide(BigInteger.valueOf(2));
			ans = min(ans, aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps)));
		}
        out.println(ans);
        out.close();
	}

    static class InputReader
	{
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream)
		{
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String nextString()
		{
            while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
                try { tokenizer = new StringTokenizer(reader.readLine()); }
                catch (IOException e) { throw new RuntimeException(e); }
            }
            return tokenizer.nextToken();
        }

        public int nextInt()
		{
            return Integer.parseInt(nextString());
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 10100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 227 ms 25676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 9696 KB Output is correct
2 Correct 78 ms 9784 KB Output is correct
3 Correct 81 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 134 ms 15288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 10144 KB Output is correct
2 Incorrect 83 ms 10116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 126 ms 13516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 214 ms 22128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 183472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 186460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1112 ms 182060 KB Time limit exceeded
2 Halted 0 ms 0 KB -