結果

問題 No.1087 転倒数の転倒数
ユーザー QCFium
提出日時 2020-05-19 18:29:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 602 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 167,384 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-07 04:41:44
合計ジャッジ時間 11,749 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 RE * 2
other AC * 15 RE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

int main() {
	int n = ri();
	int k = ri();
	if (k > n * (n - 1) * 2) {
		puts("No");
		return 0;
	}
	assert((k & 1) == 0);
	k /= 2;
	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);
	
	puts("Yes");
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) printf(" ");
			printf("%d", a[i] != j);
		}
		puts("");
	}
	
	return 0;
}
0