Submission #84033

# Submission time Handle Problem Language Result Execution time Memory
84033 2018-11-12T13:02:07 Z wjoao Prosjecni (COCI16_prosjecni) C++11
120 / 120
3 ms 668 KB
#include<bits/stdc++.h>

using namespace std;

int n;

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

  if( n == 1 ) printf("1\n");
  else if( n == 2 ) printf("-1\n");
  else if (n%2 == 1){
    for(int i = 0, k = 1; i < n; i++){
      for(int j = 0; j < n; j++, k++){
        if( j != 0 ) printf(" ");
        printf("%d", k);
      }
      printf("\n");
    }
  }else{
    vector<int> ind;
    int meio = n*100*100;
    ind.push_back(0);
    for(int i = 1; i <= n/2; i++) ind.push_back(-i);
    for(int i = 1; i <= n/2-2; i++) ind.push_back(i);
    ind.push_back(n-1);

    for(int i = 0; i < n; i++){
      int atual = meio + ind[i]*2*n;
      for(int j = 0; j < n; j++){
        if( j != 0 ) printf(" ");
        printf("%d", atual + ind[j]);
      }printf("\n");
    }
  }

  return 0;
}

Compilation message

prosjecni.cpp: In function 'int main()':
prosjecni.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %d", &n);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 3 ms 668 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 3 ms 668 KB Output is correct
10 Correct 3 ms 668 KB Output is correct