結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー ecottea
提出日時 2024-02-03 00:21:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 197,732 KB
最終ジャッジ日時 2025-02-19 01:05:33
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;


int main() {
	int n;
	cin >> n;

	if (n == 1) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> a2{ 1, 4 }, b2{ 3, 6 }, c2{ 5, 2 };
	vector<int> a3{ 1, 2, 9 }, b3{ 6, 8, 7 }, c3{ 3, 4, 5 };
	vector<int> a4{ 1, 2, 4, 11 }, b4{ 7, 9, 10, 12 }, c4{ 8, 5, 6, 3 };

	vector<int> a, b, c;
	if (n % 3 == 2) a = a2, b = b2, c = c2;
	else if (n % 3 == 0) a = a3, b = b3, c = c3;
	else a = a4, b = b4, c = c4;

	int len = (int)a.size();
	while (len < n) {
		for (auto x : a3) a.push_back(x + 3 * len);
		for (auto x : b3) b.push_back(x + 3 * len);
		for (auto x : c3) c.push_back(x + 3 * len);
		len += 3;
	}

	for (int i = 0; i < n; i++) cout << a[i] << " ";
	for (int i = 0; i < n; i++) cout << b[i] << " ";
	for (int i = 0; i < n; i++) cout << c[i] << " \n"[i == n - 1];
}
0