結果

問題 No.1434 Make Maze
ユーザー shojin_proshojin_pro
提出日時 2021-03-19 22:36:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 9,507 bytes
コンパイル時間 4,804 ms
コンパイル使用メモリ 79,548 KB
実行使用メモリ 56,768 KB
最終ジャッジ日時 2023-08-12 03:14:19
合計ジャッジ時間 12,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 45 ms
50,168 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 44 ms
50,028 KB
testcase_06 AC 44 ms
49,820 KB
testcase_07 AC 45 ms
49,776 KB
testcase_08 WA -
testcase_09 AC 44 ms
49,648 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 46 ms
49,848 KB
testcase_21 AC 62 ms
52,000 KB
testcase_22 AC 57 ms
51,136 KB
testcase_23 AC 43 ms
49,832 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static FastScanner sc = new FastScanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws Exception {
        if (args.length == 1 && args[0].equals("debug")) {
            FileReader filereader;
            BufferedReader is;
            String path = new File(".").getAbsoluteFile().getParent();
            String input = path + File.separator + "_debug_";
            String output = path + File.separator + "_answer_" + File.separator;
            File[] list = new File(input).listFiles();
            for (File file : list) {
                filereader = new FileReader(file);
                sc = new FastScanner(filereader);
                pw.println(file.getName());
                pw.println("----------------------------------------");
                pw.println("output");
                long start = System.currentTimeMillis();
                solve();
                if (new File(output + file.getName()).exists()) {
                    pw.println("----------------------------------------");
                    pw.println("expect");
                    filereader = new FileReader(new File(output + file.getName()));
                    is = new BufferedReader(filereader);
                    String s;
                    while ((s = is.readLine()) != null) {
                        pw.println(s);
                    }
                }
                pw.println("----------------------------------------");
                pw.println((System.currentTimeMillis() - start) + "ms\n");
            }
        } else {
            solve();
        }
        pw.flush();
    }

    public static void solve() {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int x = sc.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i % 2 == 0 && j % 2 == 0){
                    map[i][j] = '.';
                }else if(i % 2 == 1 && j % 2 == 1){
                    map[i][j] = '#';
                }else{
                    map[i][j] = '?';
                }
            }
        }
        int max = Math.max((h-1)/2*(w-1)+(h-1),(w-1)/2*(h-1)+(w-1));
        if((h-1+w-1) > x || max < x || x % 2 != 0){
            pw.println(-1);
            return;
        }else{
            int rem = x - (h-1+w-1);
            if(rem % 4 != 0){
                pw.println(-1);
                return;
            }
            if((h-1)/2*(w-1)+(h-1) <= (w-1)/2*(h-1)+(w-1)){
                int j = 0;
                for(int i = 0; i < h; i++){
                    if(i == h-1){
                        for(int k = 0; k < w; k++){
                            if(map[i][k] != '?') continue;
                            if(k >= j){
                                map[i][k] = '.';
                            }else{
                                map[i][k] = '#';
                            }
                        }
                    }else if(i % 2 != 0){
                        for(int k = 0; k < w; k++){
                            if(map[i][k] != '?') continue;
                            if(k != j){
                                map[i][k] = '#';
                            }else{
                                map[i][k] = '.';
                            }
                        }
                    }else{
                        int next = Math.min(rem/2,Math.max(w-1-j,j));
                        if(j+next < w){
                            for(int k = 0; k < w; k++){
                                if(map[i][k] != '?') continue;
                                if(j <= k && k <= j+next){
                                    map[i][k] = '.';
                                }else{
                                    map[i][k] = '#';
                                }
                            }
                            j += next;
                        }else{
                            for(int k = 0; k < w; k++){
                                if(map[i][k] != '?') continue;
                                if(j-next <= k && k <= j){
                                    map[i][k] = '.';
                                }else{
                                    map[i][k] = '#';
                                }
                            }
                            j -= next;
                            rem -= next*2;
                        }
                    }
                }
            }else{
                int i = 0;
                for(int j = 0; j < w; j++){
                    if(j == w-1){
                        for(int k = 0; k < h; k++){
                            if(map[k][j] != '?') continue;
                            if(k < i){
                                map[k][j] = '#';
                            }else{
                                map[k][j] = '.';
                            }
                        }
                    }else if(j % 2 != 0){
                        for(int k = 0; k < h; k++){
                            if(map[k][j] != '?') continue;
                            if(k != i){
                                map[k][j] = '#';
                            }else{
                                map[k][j] = '.';
                            }
                        }
                    }else{
                        int next = Math.min(rem/2,Math.max(h-1-i,i));
                        if(i+next < h){
                            for(int k = 0; k < h; k++){
                                if(map[k][j] != '?') continue;
                                if(i <= k && k <= i+next){
                                    map[k][j] = '.';
                                }else{
                                    map[k][j] = '#';
                                }
                            }
                            i += next;
                        }else{
                            for(int k = 0; k < h; k++){
                                if(map[k][j] != '?') continue;
                                if(i-next <= k && k <= i){
                                    map[k][j] = '.';
                                }else{
                                    map[k][j] = '#';
                                }
                            }
                            i -= next;
                            rem -= next*2;
                        }
                    }
                }
            }
        }
        for(int i = 0; i < h; i++) pw.println(new String(map[i]));
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

        public static void save_sort(long[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static long[] shuffle(long[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                long randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public FastScanner(FileReader in) {
        reader = new BufferedReader(in);
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}
0