結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー binapbinap
提出日時 2024-04-06 05:23:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,283 bytes
コンパイル時間 5,044 ms
コンパイル使用メモリ 267,632 KB
実行使用メモリ 11,524 KB
最終ジャッジ日時 2024-04-06 05:23:20
合計ジャッジ時間 10,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 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 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 59 ms
7,552 KB
testcase_16 AC 69 ms
11,404 KB
testcase_17 AC 43 ms
7,348 KB
testcase_18 AC 69 ms
11,428 KB
testcase_19 AC 57 ms
7,444 KB
testcase_20 AC 39 ms
6,844 KB
testcase_21 AC 70 ms
11,440 KB
testcase_22 AC 49 ms
7,588 KB
testcase_23 AC 46 ms
7,060 KB
testcase_24 AC 39 ms
7,180 KB
testcase_25 AC 72 ms
11,524 KB
testcase_26 AC 72 ms
11,524 KB
testcase_27 AC 91 ms
11,396 KB
testcase_28 AC 74 ms
11,524 KB
testcase_29 AC 71 ms
11,524 KB
testcase_30 AC 72 ms
11,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

int main(){
	vector<vector<int>> ans2 = {{1, 4}, {3, 6}, {5, 2}};
	vector<vector<int>> ans3 = {{1, 2, 9}, {6, 8, 7}, {3, 4, 5}};
	vector<vector<int>> ans4 = {{1, 2, 5, 12}, {8, 10, 11, 9}, {3, 6, 4, 7}};
	int n;
	cin >> n;
	if(n == 1){
		cout << "-1\n";
		return 0;
	}
	int shift = 0;
	vector<vector<int>> ans;
	if(n % 3 == 2){
		ans = ans2;
		n -= 2;
		shift = 6;
	}else if(n % 3 == 0){
		ans = ans3;
		n -= 3;
		shift = 9;
	}else if(n % 3 == 1){
		ans = ans4;
		n -= 4;
		shift = 12;
	}
	while(n >= 3){
		rep(i, 3){
			rep(j, 3) ans[i].push_back(ans3[i][j] + shift);
		}
		shift += 9;
		n -= 3;
	}
	auto judge = [&]{
		long long prod = 0;
		int n = ans[0].size();
		rep(i, n) prod += ans[0][i] * ans[1][i];
		rep(i, n) prod -= ans[1][i] * ans[2][i];
		if(prod == 0) return true;
		else return false;
	};
//	if(judge()) cout << "OK\n";
//	else cout << "NG\n";
	vector<int> res;
	rep(i, 3){
		for(int x : ans[i]) res.push_back(x);
	}
	cout << res;
	return 0;
}
0