QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527893#8217. King's Dinnersroid_03#WA 15ms10796kbPython32.7kb2024-08-22 21:49:332024-08-22 21:49:33

Judging History

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

  • [2024-08-22 21:49:33]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:10796kb
  • [2024-08-22 21:49:33]
  • 提交

answer

from sys import stdin
input = lambda: stdin.buffer.readline().decode().strip()


def solve(ans):
    ct = 0
    for x in ans:
        ct += x.count('#')
    return ct >> 1


for _ in range(int(input())):
    n = int(input())

    if n == 6:
        ans = ['##.##.', 
                '.....#', 
                '##.#.#',
                '...#..',
                '#....#',
                '#.##.#']
        print('\n'.join(ans))

    else:
        x, y = 0, 0
        while 2*(x+1) - 1 <= n and n - (2*(x+1) - 1) != 1:
            x += 1
        
        while 3*(y+1) - 1 <= n and n - (3*(y+1) - 1) != 1:
            y += 1

        ans = [['.' for _ in range(n)] for _ in range(n)]
        dx, dy = n-(2*x-1), n-(3*y-1)

        for i in range(dx, n, 2):
            for j in range(dy, n, 3):
                ans[i][j] = '#'
                ans[i][j+1] = '#'
        

        if dx == 3:
            for j in range(n-1, max(1, dy-1), -2):
                ans[0][j] = ans[1][j] = '#'

        if dy >= 2:
            for i in range(n-1, max(1, dx-1), -3):
                # print(n, i, dx)
                ans[i][0] = ans[i-1][0] = '#'
                if dy == 4:
                    ans[i][2] = ans[i-1][2] = '#'

        if n > 3:
            if '#' not in ans[0][:3] and '#' not in ans[1][:3]:
                ans[0][0] = ans[0][1] = '#'

        
        x, y = 0, 0
        while 2*(x+1) - 1 <= n:
            x += 1
        
        while 3*(y+1) - 1 <= n and n - (3*(y+1) - 1) != 1:
            y += 1

        ans2 = [['.' for _ in range(n)] for _ in range(n)]
        dx, dy = n-(2*x-1), n-(3*y-1)

        for i in range(dx, n, 2):
            for j in range(dy, n, 3):
                ans2[i][j] = '#'
                ans2[i][j+1] = '#'
        

        if dx == 3:
            for j in range(n-1, max(1, dy-1), -2):
                ans2[0][j] = ans2[1][j] = '#'

        if dy >= 2:
            for i in range(n-1, max(1, dx-1), -3):
                # print(n, i, dx)
                ans2[i][0] = ans2[i-1][0] = '#'
                if dy == 4:
                    ans2[i][2] = ans2[i-1][2] = '#'

        if n > 3:
            if '#' not in ans2[0][:3] and '#' not in ans2[1][:3]:
                ans2[0][0] = ans2[0][1] = '#'

        if solve(ans2) > solve(ans):
            ans = ans2[:]

        if n > 5:
            if '#' not in ans[1][:3] and '#' not in ans[2][:3] and '#' not in ans[3][:3]:
                ans[2][0] = ans[2][1] = '#'

            if ans[0][2] == ans[0][3] == ans[0][4] == ans[1][2] == ans[1][3] == ans[1][4] == '.':
                ans[0][3] = ans[1][3] = '#'

        for x in ans:
            print(''.join(x))

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 10584kb

input:

3
1
2
3

output:

.
..
##
...
#.#
#.#

result:

ok all tests correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 10796kb

input:

50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

output:

.
..
##
...
#.#
#.#
##.#
...#
#...
#.##
##.##
.....
##.##
.....
##.##
##.##.
.....#
##.#.#
...#..
#....#
#.##.#
..##.##
.......
#.##.##
#......
..##.##
#......
#.##.##
##.#.#.#
...#.#.#
........
##.##.##
........
##.##.##
........
##.##.##
....##.##
#.#......
#.#.##.##
.........
#.#.##.##
#.#......
...

result:

wrong answer grid contains two dominoes that are adjacent (test case 6)