結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー shobonvipshobonvip
提出日時 2024-04-06 10:36:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 4,795 ms
コンパイル使用メモリ 266,040 KB
実行使用メモリ 11,524 KB
最終ジャッジ日時 2024-04-06 10:37:05
合計ジャッジ時間 9,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 47 ms
7,552 KB
testcase_16 AC 54 ms
11,404 KB
testcase_17 AC 34 ms
6,964 KB
testcase_18 AC 55 ms
11,428 KB
testcase_19 AC 45 ms
7,444 KB
testcase_20 AC 31 ms
6,844 KB
testcase_21 AC 55 ms
11,440 KB
testcase_22 AC 39 ms
7,204 KB
testcase_23 AC 36 ms
7,060 KB
testcase_24 AC 30 ms
6,796 KB
testcase_25 AC 57 ms
11,524 KB
testcase_26 AC 57 ms
11,524 KB
testcase_27 AC 57 ms
11,524 KB
testcase_28 AC 59 ms
11,524 KB
testcase_29 AC 57 ms
11,524 KB
testcase_30 AC 56 ms
11,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

void validation(int n, vector<int> p){
	assert(p.size() == 3 * n);
	vector<int> dar(3 * n);
	rep(i,0,3 * n){
		assert(1 <= p[i] && p[i] <= 3 * n);
		assert(dar[p[i] - 1] == 0);
		dar[p[i] - 1] = 1;
	}

	ll t = 0;
	rep(i,0,n){
		t += p[i] * p[i+n];
		t -= p[i+n] * p[i+2*n];
	}
	assert(t == 0);

}


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

	vector<vector<int>> small = {
		{-1},
		{-1},
		{1, 4, 3, 6, 5, 2},
		{2, 9, 1, 6, 7, 8, 5, 3, 4},
		{7, 10, 2, 8, 1, 3, 11, 9, 6, 12, 4, 5},
	};

	if (n <= 4){
		int m = small[n].size();
		//validation(n, small[n]);
		rep(i,0,m){
			cout << small[n][i] << ' ';
		}
		cout << '\n';
	}else{
		vector<int> base;
		if (n % 3 == 0){
			base = small[3];
		}else if(n % 3 == 1){
			base = small[4];
		}else if(n % 3 == 2){
			base = small[2];
		}
		vector<int> up;
		vector<int> middle;
		vector<int> down;
		
		rep(i,0,(int)base.size() / 3){
			up.push_back(base[i]);
		}
		rep(i,(int)base.size() / 3, (int)base.size() / 3 * 2){
			middle.push_back(base[i]);
		}
		rep(i,(int)base.size() / 3 * 2, (int)base.size() / 3 * 3){
			down.push_back(base[i]);
		}
		
		while((int)up.size() < n){
			int k = (int)up.size() * 3;
			rep(i,0,3){
				up.push_back(small[3][i] + k);
			}			
			rep(i,3,6){
				middle.push_back(small[3][i] + k);
			}
			rep(i,6,9){
				down.push_back(small[3][i] + k);
			}
		}

		vector<int> ans;
		for (int i: up) ans.push_back(i);
		for (int i: middle) ans.push_back(i);
		for (int i: down) ans.push_back(i);

		int m = ans.size();
		//validation(n, ans);
		rep(i,0,m){
			cout << ans[i] << ' ';
		}
		cout << '\n';


	}
}

0