답안 #734207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734207 2023-05-02T04:55:54 Z rahulverma Prosjecni (COCI16_prosjecni) Java 11
120 / 120
475 ms 14836 KB
import java.io.*;
import java.util.*;
 
public class prosjecni {
 
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		if(n == 2) {
			System.out.println(-1);
			return;
		}
		int[][] arr = new int[n][n];
		int last = 0;
		for(int i = 0; i < n - 1; i++) {
			arr[i][0] = last + 1;
			long soFar = arr[i][0];
			for(int j = 1; j < n - 1; j++) {
				arr[i][j] = arr[i][j-1]+1;
				soFar += arr[i][j];
			}
			arr[i][n-1] = (int) ((arr[i][n/2] * (n)) - soFar);
			last = arr[i][n-1];
		}
		long cols = 0;
		for(int i = 0; i < n; i++) cols += arr[i][0];
		arr[n-1][0] = (int) ((arr[n/2][0] * (n)) - cols);
		long soFar = arr[n-1][0];
		for(int i = 1; i < n-1; i++) {
			arr[n-1][i] = arr[n-1][i-1] + 1;
			soFar += arr[n-1][i];
		}
		arr[n-1][n-1] = (int) ((arr[n-1][n/2] * (n))-soFar);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}
		
	}
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 11668 KB Output is correct
2 Correct 122 ms 11112 KB Output is correct
3 Correct 119 ms 11240 KB Output is correct
4 Correct 123 ms 10860 KB Output is correct
5 Correct 131 ms 10988 KB Output is correct
6 Correct 161 ms 11428 KB Output is correct
7 Correct 227 ms 12212 KB Output is correct
8 Correct 324 ms 13388 KB Output is correct
9 Correct 344 ms 13336 KB Output is correct
10 Correct 475 ms 14836 KB Output is correct