QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527902#8217. King's Dinnersroid_03#AC ✓30ms11036kbPython32.7kb2024-08-22 22:22:172024-08-22 22:22:17

Judging History

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

  • [2024-08-22 22:22:17]
  • 评测
  • 测评结果:AC
  • 用时:30ms
  • 内存:11036kb
  • [2024-08-22 22:22:17]
  • 提交

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))

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 10616kb

input:

3
1
2
3

output:

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

result:

ok all tests correct (3 test cases)

Test #2:

score: 0
Accepted
time: 11ms
memory: 10792kb

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:

ok all tests correct (50 test cases)

Test #3:

score: 0
Accepted
time: 30ms
memory: 11036kb

input:

39
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

output:

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

result:

ok all tests correct (39 test cases)

Test #4:

score: 0
Accepted
time: 22ms
memory: 10784kb

input:

11
90
91
92
93
94
95
96
97
98
99
100

output:

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

result:

ok all tests correct (11 test cases)

Test #5:

score: 0
Accepted
time: 8ms
memory: 10800kb

input:

1
100

output:

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

result:

ok all tests correct (1 test case)

Extra Test:

score: 0
Extra Test Passed