답안 #416356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416356 2021-06-02T10:36:03 Z model_code Diamond Hands (innopolis2021_final_B) Java 11
컴파일 오류
0 ms 0 KB
import java.io.*;
import java.util.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class polyline_av_n2 {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Polyline solver = new Polyline();
        solver.solve(1, in, out);
        out.close();
    }

    static class Polyline {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int MAX = 2000;
            int INF = Integer.MAX_VALUE / 2;
            int[] hasY = new int[MAX + 1];
            Arrays.fill(hasY, INF);
            hasY[0] = 0;
            int lastX = -1;
            for (int i = 0; i <n; i++) {
                int x = in.nextInt();
                hasY[x] = in.nextInt();
                if (i + 1 == n) {
                    lastX = x;
                }
            }
            int[][][] dp = new int[2][lastX + 1][2 * MAX + 1];
            int[][][] pr = new int[2][lastX + 1][2 * MAX + 1];
            for (int[][] i : dp) {
                for (int[] j : i) {
                    Arrays.fill(j, INF);
                }
            }
            dp[0][0][0 + MAX] = dp[1][0][0 + MAX] = 0;
            for (int x = 0; x < lastX; x++) {
                int startY = -MAX, endY = MAX;
                if (hasY[x] != INF) {
                    startY = endY = hasY[x];
                }
                for (int y = startY; y <= endY; y++) {
                    for (int d = 0; d < 2; d++) {
                        int val = dp[d][x][y + MAX];
                        if (val != INF) {
                            for (int newD = 0; newD < 2; newD++) {
                                int newVal = val + ((d == newD) ? 0 : 1);
                                if (dp[newD][x + 1][y + MAX + (2 * newD - 1)] > newVal) {
                                    dp[newD][x + 1][y + MAX + (2 * newD - 1)] = newVal;
                                    pr[newD][x + 1][y + MAX + (2 * newD - 1)] = d;
                                }
                            }
                        }
                    }
                }
            }
            int bestD = dp[0][lastX][hasY[lastX] + MAX] < dp[1][lastX][hasY[lastX] + MAX] ? 0 : 1;
            if (dp[bestD][lastX][hasY[lastX] + MAX] == INF) {
                out.println(-1);
            } else {
                List<Integer> ls = new ArrayList<>();
                List<Character> cs = new ArrayList<>();
                int curY = hasY[lastX], curD = bestD;
                for (int curX = lastX; curX > 0; curX--) {
                    int prevD = pr[curD][curX][curY + MAX];
                    char c = curD == 1 ? '+' : '-';
                    if (cs.size() > 0 && cs.get(cs.size() - 1) == c) {
                        ls.set(ls.size() - 1, ls.get(ls.size() - 1) + 1);
                    } else {
                        ls.add(1);
                        cs.add(c);
                    }
                    curY -= 2 * curD - 1;
                    curD = prevD;
                }
                out.println(ls.size());
                for (int i = ls.size() - 1; i >= 0; i--) {
                    out.println(ls.get(i) + " " + cs.get(i));
                }
            }
        }

    }

    static class FastScanner {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (line == null) {
                    throw new UnknownError();
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }
}

Compilation message

Main.java:8: error: class polyline_av_n2 is public, should be declared in a file named polyline_av_n2.java
public class polyline_av_n2 {
       ^
1 error