結果

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

テストケース

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

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

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

	for (int i = 0; i < N; i++){
		int p = m ? (N - i) * 10000 : (i + 1) * 10000;
		if (K >= N * (N - 1) / 2){
			K -= N * (N - 1) / 2;
			for (int j = 0; j < N; j++){
				A[i][j] = p + N - j;
			}
		}
		else if (K == 0){
			for (int j = 0; j < N; j++){
				A[i][j] = p + j;
			}
		}
		else{
			auto v = make(N, K);
			for (int j = 0; j < N; j++){
				A[i][j] = p + v[j];
			}
		}
	}

	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