답안 #74105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74105 2018-08-30T05:56:28 Z charlies_moo Prosjecni (COCI16_prosjecni) C++17
120 / 120
4 ms 504 KB
#include <cstdio>

int main() {
    int n;
    scanf("%d", &n);

    if (n == 2) {
        printf("-1\n");
    } else if (n % 2 == 1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                printf("%d%c", i*n+j+1, j==n-1 ? '\n' : ' ');
            }
        }
    } else {
        int k = n / 2;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - 1; j++) {
                printf("%d ", 3*k*i+j+1);
            }
            printf("%d\n", 3*k*(i+1));
        }
        for (int j = 0; j < n - 1; j++) {
            printf("%d ", 9*k*k-3*k+j+1);
        }
        printf("%d\n", 9*k*k);
    }

    return 0;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:5:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 2 ms 440 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct