Submission #117071

# Submission time Handle Problem Language Result Execution time Memory
117071 2019-06-14T15:30:27 Z emilem Board (CEOI13_board) C++14
Compilation error
0 ms 0 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());
        }
    }
}

Compilation message

board.cpp:1:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.OutputStream;
 ^~~~~~
 short
board.cpp:2:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.IOException;
 ^~~~~~
 short
board.cpp:3:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.InputStream;
 ^~~~~~
 short
board.cpp:4:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.PrintWriter;
 ^~~~~~
 short
board.cpp:5:1: error: 'import' does not name a type; did you mean 'short'?
 import java.util.StringTokenizer;
 ^~~~~~
 short
board.cpp:6:1: error: 'import' does not name a type; did you mean 'short'?
 import java.math.BigInteger;
 ^~~~~~
 short
board.cpp:7:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.IOException;
 ^~~~~~
 short
board.cpp:8:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.BufferedReader;
 ^~~~~~
 short
board.cpp:9:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.InputStreamReader;
 ^~~~~~
 short
board.cpp:10:1: error: 'import' does not name a type; did you mean 'short'?
 import java.io.InputStream;
 ^~~~~~
 short
board.cpp:14:12: error: 'BigInteger' does not name a type
     static BigInteger min(BigInteger a, BigInteger b)
            ^~~~~~~~~~
board.cpp:18:19: error: 'String' has not been declared
  static int Depth(String a)
                   ^~~~~~
board.cpp:28:9: error: 'BigInteger' does not name a type
  static BigInteger Coord(String a)
         ^~~~~~~~~~
board.cpp:48:12: error: expected ':' before 'static'
     public static void main(String[] args)
            ^~~~~~
board.cpp:48:29: error: 'String' has not been declared
     public static void main(String[] args)
                             ^~~~~~
board.cpp:48:38: error: expected ',' or '...' before 'args'
     public static void main(String[] args)
                                      ^~~~
board.cpp:86:16: error: expected ':' before 'BufferedReader'
         public BufferedReader reader;
                ^~~~~~~~~~~~~~
board.cpp:86:16: error: 'BufferedReader' does not name a type
board.cpp:87:16: error: expected ':' before 'StringTokenizer'
         public StringTokenizer tokenizer;
                ^~~~~~~~~~~~~~~
board.cpp:87:16: error: 'StringTokenizer' does not name a type
board.cpp:89:16: error: expected ':' before 'InputReader'
         public InputReader(InputStream stream)
                ^~~~~~~~~~~
board.cpp:89:40: error: expected ')' before 'stream'
         public InputReader(InputStream stream)
                                        ^~~~~~
board.cpp:95:16: error: expected ':' before 'String'
         public String nextString()
                ^~~~~~
board.cpp:95:16: error: 'String' does not name a type
board.cpp:105:16: error: expected ':' before 'int'
         public int nextInt()
                ^~~
board.cpp:109:6: error: expected ';' after class definition
     }
      ^
      ;
board.cpp:84:5: error: a storage class can only be specified for objects and functions
     static class InputReader
     ^~~~~~
board.cpp:110:2: error: expected ';' after class definition
 }
  ^
  ;
board.cpp: In static member function 'static int board::Depth(int)':
board.cpp:21:25: error: request for member 'length' in 'a', which is of non-class type 'int'
   for (int i = 0; i < a.length(); ++i)
                         ^~~~~~
board.cpp:22:10: error: request for member 'charAt' in 'a', which is of non-class type 'int'
    if (a.charAt(i) == 'U')
          ^~~~~~
board.cpp:24:15: error: request for member 'charAt' in 'a', which is of non-class type 'int'
    else if (a.charAt(i) == '1' || a.charAt(i) == '2')
               ^~~~~~
board.cpp:24:37: error: request for member 'charAt' in 'a', which is of non-class type 'int'
    else if (a.charAt(i) == '1' || a.charAt(i) == '2')
                                     ^~~~~~
board.cpp: In static member function 'static void board::main(int*)':
board.cpp:50:9: error: 'InputStream' was not declared in this scope
         InputStream inputStream = System.in;
         ^~~~~~~~~~~
board.cpp:51:9: error: 'OutputStream' was not declared in this scope
         OutputStream outputStream = System.out;
         ^~~~~~~~~~~~
board.cpp:52:42: error: 'inputStream' was not declared in this scope
         InputReader in = new InputReader(inputStream);
                                          ^~~~~~~~~~~
board.cpp:53:9: error: 'PrintWriter' was not declared in this scope
         PrintWriter out = new PrintWriter(outputStream);
         ^~~~~~~~~~~
board.cpp:54:3: error: 'String' was not declared in this scope
   String path = in.nextString();
   ^~~~~~
board.cpp:55:22: error: 'path' was not declared in this scope
   int aDepth = Depth(path);
                      ^~~~
board.cpp:56:3: error: 'BigInteger' was not declared in this scope
   BigInteger aCoord = Coord(path);
   ^~~~~~~~~~
board.cpp:57:13: error: 'class board::InputReader' has no member named 'nextString'; did you mean 'nextInt'?
   path = in.nextString();
             ^~~~~~~~~~
             nextInt
board.cpp:59:14: error: expected ';' before 'bCoord'
   BigInteger bCoord = Coord(path);
              ^~~~~~
board.cpp:60:13: error: 'bCoord' was not declared in this scope
   int iii = bCoord.intValue();
             ^~~~~~
board.cpp:60:13: note: suggested alternative: 'board'
   int iii = bCoord.intValue();
             ^~~~~~
             board
board.cpp:65:15: error: expected ';' before 'temp2'
    BigInteger temp2;
               ^~~~~
board.cpp:66:4: error: 'temp2' was not declared in this scope
    temp2 = aCoord; aCoord = bCoord; bCoord = temp2;
    ^~~~~
board.cpp:66:4: note: suggested alternative: 'temp1'
    temp2 = aCoord; aCoord = bCoord; bCoord = temp2;
    ^~~~~
    temp1
board.cpp:66:12: error: 'aCoord' was not declared in this scope
    temp2 = aCoord; aCoord = bCoord; bCoord = temp2;
            ^~~~~~
board.cpp:66:12: note: suggested alternative: 'board'
    temp2 = aCoord; aCoord = bCoord; bCoord = temp2;
            ^~~~~~
            board
board.cpp:71:14: error: expected ';' before 'ans'
   BigInteger ans = aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps));
              ^~~
board.cpp:76:4: error: 'aCoord' was not declared in this scope
    aCoord = aCoord.divide(BigInteger.valueOf(2));
    ^~~~~~
board.cpp:76:4: note: suggested alternative: 'board'
    aCoord = aCoord.divide(BigInteger.valueOf(2));
    ^~~~~~
    board
board.cpp:78:4: error: 'ans' was not declared in this scope
    ans = min(ans, aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps)));
    ^~~
board.cpp:78:10: error: 'min' was not declared in this scope
    ans = min(ans, aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps)));
          ^~~
board.cpp:78:10: note: suggested alternative: 'main'
    ans = min(ans, aCoord.subtract(bCoord).abs().add(BigInteger.valueOf(depthSteps)));
          ^~~
          main
board.cpp:80:9: error: 'out' was not declared in this scope
         out.println(ans);
         ^~~
board.cpp:80:9: note: suggested alternative: 'auto'
         out.println(ans);
         ^~~
         auto
board.cpp:80:21: error: 'ans' was not declared in this scope
         out.println(ans);
                     ^~~
board.cpp:60:7: warning: unused variable 'iii' [-Wunused-variable]
   int iii = bCoord.intValue();
       ^~~
board.cpp: In member function 'int board::InputReader::nextInt()':
board.cpp:107:20: error: 'Integer' was not declared in this scope
             return Integer.parseInt(nextString());
                    ^~~~~~~
board.cpp:107:20: note: suggested alternative: 'InputReader'
             return Integer.parseInt(nextString());
                    ^~~~~~~
                    InputReader
board.cpp:107:37: error: 'nextString' was not declared in this scope
             return Integer.parseInt(nextString());
                                     ^~~~~~~~~~
board.cpp:107:37: note: suggested alternative: 'nextInt'
             return Integer.parseInt(nextString());
                                     ^~~~~~~~~~
                                     nextInt