結果

問題 No.1087 転倒数の転倒数
ユーザー kriiikriii
提出日時 2020-06-19 23:22:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 50,260 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-16 15:36:28
合計ジャッジ時間 14,304 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,980 KB
testcase_02 AC 2 ms
5,044 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
5,048 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 94 ms
8,904 KB
testcase_18 AC 2 ms
5,004 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
using namespace std;

int N, K;

vector<int> make(int n, int v)
{
	vector<int> ret;
	int s = 0, e = n - 1;
	for (int i = 0; i < n; i++){
		if (v >= e - s){
			v -= e - s;
			ret.push_back(e);
			e--;
		}
		else{
			ret.push_back(s);
			s++;
		}
	}
	return ret;
}

int A[1010][1010], B[1010][1010];

int main()
{
	scanf ("%d %d", &N, &K);
	int L = N * (N - 1);

	if (K > L){
		puts("No");
		return 0;
	}

	if (K >= L / 2){
		K -= L / 2;
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++) B[j][i] = j;
			for (int k = 0; k < i; k++) swap(B[k][i], B[k + 1][i]);
		}
	}

	vector<int> v = make(N, K);
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++) A[i][j] = j;
		for (int k = 0; k < v[i]; k++) swap(A[i][k], A[i][k + 1]);
	}

	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++) A[i][j] += B[i][j] * 10000;
	}

	puts("Yes");
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++) printf ("%d%c", A[i][j], j + 1 < N ? ' ' : '\n');
	}
	return 0;
}
0