結果

問題 No.1087 転倒数の転倒数
ユーザー QCFiumQCFium
提出日時 2020-05-19 19:03:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 170,064 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-16 08:45:23
合計ジャッジ時間 13,005 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 84 ms
7,444 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 83 ms
7,580 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 68 ms
6,680 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 63 ms
6,476 KB
testcase_26 AC 58 ms
6,488 KB
testcase_27 AC 37 ms
5,164 KB
testcase_28 AC 34 ms
5,124 KB
testcase_29 AC 46 ms
5,804 KB
testcase_30 AC 23 ms
4,528 KB
testcase_31 AC 62 ms
6,596 KB
testcase_32 AC 62 ms
6,396 KB
testcase_33 AC 38 ms
5,456 KB
testcase_34 AC 83 ms
7,472 KB
testcase_35 AC 83 ms
7,444 KB
testcase_36 AC 83 ms
7,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int k = ri();
	if (n == 2 && k == 1) {
		puts("Yes\n1 0\n2 2");
		return 0;
	}
	if (k > n * (n - 1)) {
		puts("No");
		return 0;
	}
	int big = std::min(k, 2 * (n - 1));
	if ((k & 1) && !(big & 1)) big--;
	k = (k - big) >> 1;
	
	n--;
	int a[n];
	std::iota(a, a + n, 0);
	int cur = n - 1, cnt = 0;
	while (k && k >= cur) k -= cur, cur--, cnt++;
	std::rotate(a, a + cnt, a + n);
	std::reverse(a + n - cnt, a + n);
	if (k) std::rotate(a, a + 1, a + k + 1);
	
	n++;
	int left = big / 2;
	int right = big - left;
	
	std::vector<std::vector<int> > res(n, std::vector<int> (n));
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) res[i][j] = a[i - (i >= left)] != j - (j >= right);
	for (int i = 0; i < n; i++) res[left][i] = res[i][right] = 2;
	if (right == n - 1) for (auto &i : res) for (auto &j : i) j = j == 2 ? 0 : j + 1;
	
	puts("Yes");
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) printf(" ");
			printf("%d", res[i][j]);
		}
		puts("");
	}
	
	return 0;
}
0