Submission #7224168


Source Code Expand

Copy
#!/usr/bin/env python3
def solve(n):
    if n % 2 == 0:
        return

    # construct
    a = [ [ 1 + x * n + y for x in range(n) ] for y in range(n) ]
    for y in range(n // 2):
        a[y][n - 1], a[n - y - 1][n - 1] = a[n - y - 1][n - 1], a[y][n - 1]
    for z in range(n):
        a[z][n - 1], a[z][z] = a[z][z], a[z][n - 1]

    # check
    assert len(set([ sum([ a[y][x] for x in range(n) ]) % n for y in range(n) ])) == n
    assert len(set([ sum([ a[y][x] for y in range(n) ]) % n for x in range(n) ])) == n

    return a

def main():
    n = int(input())
    a = solve(n)
    if a is None:
        print('No')
    else:
        print('Yes')
        for row in a:
            print(*row)

main()

Submission Info

Submission Time
Task E - N法陣
User kimiyuki
Language Python3 (3.4.3)
Score 100
Code Size 708 Byte
Status
Exec Time 821 ms
Memory 50492 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_sample_00, 00_sample_01
All 100 / 100 00_sample_00, 00_sample_01, 02_random_01, 02_random_02, 02_random_03, 02_random_04, 02_random_05, 02_random_06, 02_random_07, 02_random_08, 02_random_09, 02_random_10, 03_min_01, 03_min_02, 03_min_03, 03_min_04, 03_min_05, 04_max_01, 04_max_02, 04_max_03, 04_max_04, 04_max_05, 04_max_06, 04_max_07, 04_max_08, 04_max_09
Case Name Status Exec Time Memory
00_sample_00 18 ms 3064 KB
00_sample_01 17 ms 3064 KB
02_random_01 17 ms 3064 KB
02_random_02 273 ms 18700 KB
02_random_03 17 ms 3064 KB
02_random_04 163 ms 12492 KB
02_random_05 17 ms 3064 KB
02_random_06 22 ms 3680 KB
02_random_07 154 ms 12488 KB
02_random_08 296 ms 21872 KB
02_random_09 188 ms 14772 KB
02_random_10 17 ms 3064 KB
03_min_01 17 ms 3064 KB
03_min_02 17 ms 3064 KB
03_min_03 18 ms 3064 KB
03_min_04 18 ms 3064 KB
03_min_05 17 ms 3064 KB
04_max_01 17 ms 3064 KB
04_max_02 749 ms 50492 KB
04_max_03 17 ms 3064 KB
04_max_04 744 ms 50372 KB
04_max_05 17 ms 3064 KB
04_max_06 821 ms 50108 KB
04_max_07 752 ms 46060 KB
04_max_08 745 ms 46268 KB
04_max_09 698 ms 46428 KB