QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72971#2898. Diagonalscodingsword#TL 370ms143756kbJava113.7kb2023-01-21 06:19:252023-01-21 06:19:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-21 06:19:28]
  • 评测
  • 测评结果:TL
  • 用时:370ms
  • 内存:143756kb
  • [2023-01-21 06:19:25]
  • 提交

answer

import java.util.*;

public class c {
    static int n;
    static char[][] input;
    static char[][] answer;

    static byte[] makeDSU(int n) {
        byte[] res = new byte[n];
        Arrays.fill(res, (byte)-1);
        return res;
    }

    static byte find(byte[] s, byte i) {
        return s[i] < (byte)0 ? i : (s[i] = find(s, s[i]));
    }

    static boolean union(byte[] s, byte a, byte b) {
        if ((a = find(s, a)) == (b = find(s, b))) return false;
        if (s[a] == s[b]) s[a]--;
        if (s[a] <= s[b]) s[b] = a;
        else s[a] = b;
        return true;
    }
    
    static int countIngoing(int i, int j) {
        int result = 0;
        if (i < n && j < n && answer[i][j] == '\\') result += 1;
        if (i > 0 && j < n && answer[i - 1][j] == '/') result += 1;
        if (i < n && j > 0 && answer[i][j - 1] == '/') result += 1;
        if (i > 0 && j > 0 && answer[i - 1][j - 1] == '\\') result += 1;

        return result;
    }

    static int countPerpendicular(int i, int j) {
        int result = 0;
        if (i < n && j < n && answer[i][j] == '/') result += 1;
        if (i > 0 && j < n && answer[i - 1][j] == '\\') result += 1;
        if (i < n && j > 0 && answer[i][j - 1] == '\\') result += 1;
        if (i > 0 && j > 0 && answer[i - 1][j - 1] == '/') result += 1;

        return result;
    }

    static int countUnknown(int i, int j) {
        int result = 0;
        if (i < n && j < n && answer[i][j] == 0) result += 1;
        if (i > 0 && j < n && answer[i - 1][j] == 0) result += 1;
        if (i < n && j > 0 && answer[i][j - 1] == 0) result += 1;
        if (i > 0 && j > 0 && answer[i - 1][j - 1] == 0) result += 1;

        return result;
    }

    static boolean verify(int i, int j) {
        if (input[i][j] == '+') return true;
        int expected = input[i][j] - '0';
        int ingoing = countIngoing(i, j);
        int unknown = countUnknown(i, j);
        if (ingoing > expected) return false;
        if (ingoing + unknown < expected) return false;

        return true;
    }

    static byte[] dsu;

    static boolean solve(int i, int j) {
        if (i == n) {
            return true;
        }

        int ni = i, nj = j + 1;
        if (nj == n) {
            ni += 1;
            nj = 0;
        }

        byte[] save = dsu;

        byte A = (byte)(i * (n + 1) + j);
        byte B = (byte)((i + 1) * (n + 1) + (j + 1));
        if (find(dsu, A) != find(dsu, B)) {
            answer[i][j] = '\\';
            if (verify(i, j + 1) && verify(i + 1, j) && verify(i + 1, j + 1) && verify(i, j)) {
                dsu = Arrays.copyOf(dsu, dsu.length);
                union(dsu, A, B);
                if (solve(ni, nj)) return true;
                dsu = save;
            }
        }

        A = (byte)(i * (n + 1) + (j + 1));
        B = (byte)((i + 1) * (n + 1) + j);
        if (find(dsu, A) != find(dsu, B)) {
            answer[i][j] = '/';
            if (verify(i, j + 1) && verify(i + 1, j) && verify(i + 1, j + 1) && verify(i, j)) {
                dsu = Arrays.copyOf(dsu, dsu.length);
                union(dsu, A, B);
                if (solve(ni, nj)) return true;
                dsu = save;
            }
        }

        answer[i][j] = 0;
        return false;
    }
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        scan.nextLine();
        answer = new char[n][n];
        input = new char[n + 1][];
        for (int i = 0; i <= n; ++i) {
            input[i] = scan.nextLine().toCharArray();
        }

        dsu = makeDSU((n + 1) * (n + 1));
        solve(0, 0);

        for (char[] arr : answer) {
            System.out.println(String.valueOf(arr));
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 87ms
memory: 53864kb

input:

8
+11+111++
1++++1++0
1++2++3++
+1+2+1+3+
+213+++++
12+232+++
222+++22+
+++3+3+++
+211+121+

output:

////////
/\\/\//\
/\\///\\
//\/\//\
///////\
////\\\\
\\\/\///
\///\\//

result:

ok 8 lines

Test #2:

score: 0
Accepted
time: 86ms
memory: 55624kb

input:

8
++++++11+
+13+13++1
++21+21++
+11+2222+
+2++3++21
+11+1+2+1
+++322+1+
11+1+1+11
+1++1++++

output:

/\/\\///
\\\\//\/
/\\////\
\\/////\
//\/\//\
\//////\
/\/\\\//
//\\\/\/

result:

ok 8 lines

Test #3:

score: 0
Accepted
time: 112ms
memory: 56244kb

input:

8
++1+++2++
12++23++2
0222322++
+3+11+3+1
++++++++1
+213+2++0
+1+3++22+
2++22+4++
+1+++1+++

output:

\\\\\/\\
\\\\\\\/
////\\\/
/\\///\/
/\\//\\/
/\///\/\
///\/\/\
\\/\//\\

result:

ok 8 lines

Test #4:

score: 0
Accepted
time: 137ms
memory: 55052kb

input:

5
+1+2++
1++11+
+3+2++
02+++1
++3+1+
+1+++1

output:

\\/\\
\/\\/
\\\\\
////\
//\\\

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 120ms
memory: 54164kb

input:

5
+++21+
11+2++
1++2++
++32+1
+3++3+
++0+++

output:

\\/\\
\//\/
\\/\/
\//\/
//\\\

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 97ms
memory: 53964kb

input:

5
++1+++
12+++1
+2121+
+2+22+
+323++
++++1+

output:

////\
////\
\\///
\\///
/\/\\

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 266ms
memory: 99304kb

input:

8
+++++++++
++4+++22+
+3+++3+3+
++++2+3++
++1++++21
++21++3++
+2+++++21
+4+1+2+11
++++2+1+0

output:

\\//\\\/
\/\\\\\/
//\\/\//
//\\////
\//\\\//
\///////
\//\/\//
/\\\/\\/

result:

ok 8 lines

Test #8:

score: 0
Accepted
time: 97ms
memory: 53968kb

input:

1
01
10

output:

/

result:

ok single line: '/'

Test #9:

score: 0
Accepted
time: 112ms
memory: 56224kb

input:

1
0+
++

output:

/

result:

ok single line: '/'

Test #10:

score: 0
Accepted
time: 118ms
memory: 54116kb

input:

1
10
01

output:

\

result:

ok single line: '\'

Test #11:

score: 0
Accepted
time: 117ms
memory: 54180kb

input:

1
1+
++

output:

\

result:

ok single line: '\'

Test #12:

score: 0
Accepted
time: 89ms
memory: 52224kb

input:

1
+0
++

output:

\

result:

ok single line: '\'

Test #13:

score: 0
Accepted
time: 94ms
memory: 54624kb

input:

1
+1
++

output:

/

result:

ok single line: '/'

Test #14:

score: 0
Accepted
time: 112ms
memory: 54020kb

input:

1
++
0+

output:

\

result:

ok single line: '\'

Test #15:

score: 0
Accepted
time: 81ms
memory: 54076kb

input:

1
++
1+

output:

/

result:

ok single line: '/'

Test #16:

score: 0
Accepted
time: 98ms
memory: 54260kb

input:

1
++
+0

output:

/

result:

ok single line: '/'

Test #17:

score: 0
Accepted
time: 117ms
memory: 54972kb

input:

1
++
+1

output:

\

result:

ok single line: '\'

Test #18:

score: 0
Accepted
time: 128ms
memory: 57264kb

input:

8
+++++++++
+1+2+32+1
++32++4++
+2+4++++1
+3+++++11
++21++3+0
+2++23+++
++1++++1+
+110+0+10

output:

/\\/\\//
\\\//\//
\/\///\/
\//\\///
///\\\\/
\\\\\/\\
//\////\
///\/\//

result:

ok 8 lines

Test #19:

score: 0
Accepted
time: 82ms
memory: 55572kb

input:

8
+++++++++
+3+2+2+20
+2+4+3+++
++1++2++1
+3++2+++1
+++21+2+2
++2++24++
+2+3++++1
+2+112+2+

output:

\/\/\///
\\\/\/\\
///\\\\\
\\//\\/\
/\//\\/\
//\\\\//
\/\///\/
\/\\\/\/

result:

ok 8 lines

Test #20:

score: 0
Accepted
time: 125ms
memory: 55296kb

input:

7
++++++++
+23131+1
+11+1+2+
++2++1+1
+3++3+++
++22222+
+3+3222+
++2+1+2+

output:

/////\/
//\/\\/
\////\/
\//\///
\\\\\\/
\\\\\\/
/\/\\\/

result:

ok 7 lines

Test #21:

score: 0
Accepted
time: 101ms
memory: 57508kb

input:

7
++++++++
+21221+0
+++1+3++
+3+2++21
+233++2+
+++++2+1
+21+2++1
+++12+2+

output:

/////\/
\\////\
\/\//\\
\\\//\\
//\\///
//\\///
\\\\/\/

result:

ok 7 lines

Test #22:

score: 0
Accepted
time: 93ms
memory: 54820kb

input:

8
+++++++++
+2+233+21
+24++2+21
++++++1+1
+3++21+22
+23+++3++
+++3+++11
+21++21+0
+1110++1+

output:

\\\\\/\\
\\//\\\\
//\///\\
\////\\\
\\\\\\//
//\/////
//\\//\/
////\\\\

result:

ok 8 lines

Test #23:

score: 0
Accepted
time: 125ms
memory: 54828kb

input:

8
+++++++++
+11+1+4+0
++2++3+++
+131+++1+
++1+3+320
+2+2+11++
+23+1+2++
+31++1++1
+0+112+0+

output:

//\/\\//
\//\\/\\
///\///\
\/\\////
//////\\
////\//\
//\////\
/\\\\//\

result:

ok 8 lines

Test #24:

score: 0
Accepted
time: 114ms
memory: 54836kb

input:

7
++++++++
+24++1+1
++++2+3+
++23+231
+3++2+++
+33+121+
++++++2+
++0+11+1

output:

\\///\/
//\/\\/
\\\/\\\
\/////\
\\////\
/\\\///
//\\\\\

result:

ok 7 lines

Test #25:

score: 0
Accepted
time: 107ms
memory: 53332kb

input:

7
++++++++
+232+2+1
+++2++3+
+322+2++
++24+1+2
++++++2+
+2++2+4+
+0+10+++

output:

\\\//\/
//\//\/
\\\//\\
/\\//\\
///\\\/
/\//\\/
/\//\/\

result:

ok 7 lines

Test #26:

score: 0
Accepted
time: 102ms
memory: 57088kb

input:

8
+++++++++
++3+3+3++
+3+3+3+3+
++3+++3++
+3+++++2+
++3+++32+
+3+3+3+31
++3+2+3++
+++++++++

output:

\\\\\\//
\/\/\///
\\\\\\/\
\/\\/\\\
\\\/\\\\
\/\\\/\\
///\///\
//\\//\\

result:

ok 8 lines

Test #27:

score: 0
Accepted
time: 100ms
memory: 54444kb

input:

3
++++
+1+1
+31+
+0+0

output:

/\/
///
/\/

result:

ok 3 lines

Test #28:

score: 0
Accepted
time: 107ms
memory: 56376kb

input:

4
+++++
+3++2
++3++
+3+3+
++2+0

output:

\//\
\\//
\\\/
/\//

result:

ok 4 lines

Test #29:

score: 0
Accepted
time: 132ms
memory: 54936kb

input:

7
++++++++
+3+3+3++
++3++23+
+3+++321
++3+++3+
+3+++3++
++3+3+3+
+++1++++

output:

\\\/\//
/\//\\/
///\\\\
/\///\\
///\//\
/\/\/\\
//////\

result:

ok 7 lines

Test #30:

score: 0
Accepted
time: 193ms
memory: 72120kb

input:

8
+++++++++
+3+24+++2
++4+++2++
+++++21+1
+3+3++2++
++3+2++2+
+++3+++3+
++++3+3+2
+2+2+2+2+

output:

\\\\//\\
/\//\/\/
//\///\/
\\\/////
/\\\\\\/
//\//\\/
\/\\\\\\
\/\/\/\/

result:

ok 8 lines

Test #31:

score: 0
Accepted
time: 370ms
memory: 143756kb

input:

8
+++++++++
+22+2+2+1
+32+2+2+1
++2+2+1+2
++2+3++2+
+22++2+3+
++3++22+1
+3+3+++3+
++2+110++

output:

\\/\//\\
\\/\//\\
/\/\//\\
\\/\/\\/
\\/\\\\/
\\//////
\\\/\\\/
/\////\\

result:

ok 8 lines

Test #32:

score: 0
Accepted
time: 133ms
memory: 59868kb

input:

8
+++++++++
+33++3+3+
+++++33++
++3+++++1
+3+3+++2+
++3+1+32+
+++2+3+31
+1+++23++
+11+1+1++

output:

\\//\///
/\\\\\/\
\\///\\\
\\\//\\\
/\//\\//
/\\\\\\\
/\///\/\
/////\\\

result:

ok 8 lines

Test #33:

score: 0
Accepted
time: 160ms
memory: 68164kb

input:

8
+++++++++
+33++23+0
++++2++1+
++3++3+30
+3+22+2++
++3++22++
+3++++3+0
+3+223+2+
++++++2+0

output:

\\//\\//
/\\////\
\\/\\\//
\////\/\
\\\\\\/\
\/\\\\//
\\\\\\\\
/\///\//

result:

ok 8 lines

Test #34:

score: 0
Accepted
time: 333ms
memory: 111784kb

input:

8
+++++++++
++3++2+20
+3+3+1+++
++2+3+++2
+++++3+++
+2+2++3++
+1+1+3++1
++3++33++
+1+1++++0

output:

\\///\//
\\\\/\\\
/\/\//\\
/\/\\///
/\/\\\//
/\/\\///
\\//\\//
/////\\/

result:

ok 8 lines

Test #35:

score: 0
Accepted
time: 143ms
memory: 57364kb

input:

8
+++++++++
+3+1+1+22
++22222++
+2+++++22
++2+2+2++
+++2+3++2
+2++2+2++
+4+++3+22
+++11++++

output:

\//\/\\\
////////
\\\\\\\\
////////
\\\\\//\
\///////
\//\\\\\
/\///\//

result:

ok 8 lines

Test #36:

score: -100
Time Limit Exceeded

input:

8
+++++++++
+2+2+2+2+
+2+2+2+2+
+2+2+2+2+
+2+2+2+2+
+2+2+2+2+
+2+2+2+2+
+2+2+2+2+
+0+0+0+0+

output:


result: