結果

問題 No.1087 転倒数の転倒数
ユーザー kriiikriii
提出日時 2020-06-19 23:18:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 49,992 KB
実行使用メモリ 6,980 KB
最終ジャッジ日時 2023-09-16 15:30:46
合計ジャッジ時間 11,065 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 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];

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

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

	bool m = 0;
	if (K >= L / 2){
		K -= L / 2;
		m = 1;
	}

	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++){
		int p = m ? (N - i) * 10000 : (i + 1) * 10000;
		for (int j = 0; j < N; j++) A[i][j] += p;
	}

	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