답안 #166103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166103 2019-11-30T18:07:32 Z sans Prosjecni (COCI16_prosjecni) C++14
120 / 120
3 ms 504 KB
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int N; cin >> N;
    
    if(N == 2){ cout << -1 << endl; return 0; }

    if(N%2){
        int s = 1;
        for(int i = 1; i <= N; ++i){
            for(int j = 1; j <= N; ++j){
                cout << s++;
                if(j != N) cout << sp;
            }
            cout << endl;
        }
    }
    else{
        vvll grid(N, vll(N));
        grid[0][0] = 5000000; grid[0][1] = grid[0][0] - ((N-2)*(N-1)/2);
        for(int i = 2; i < N; ++i){
            grid[0][i] = grid[0][0] + i - 1;
        }
        for(int i = 1; i < N-1; ++i){
            for(int j = 0; j < N; ++j){
                grid[i][j] = grid[i-1][j] - 4000;
            }
        }
        
        ll x = ((N-2)*(N-1)/2)*4000;
        for(int i = 0; i < N; ++i){
            grid[N-1][i] = grid[0][i] + x;
        }

        ll minsayi = INF;
        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j){
                minsayi = min(minsayi, grid[i][j]);
            }
        }

        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j){
                grid[i][j] -= (minsayi-1);
            }
        }

        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j){
                cout << grid[i][j];
                if(j != N-1) cout << sp;
            }
            cout << endl;
        }
    }

    return 0;
}

//cikisir

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct