結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー 沙耶花沙耶花
提出日時 2024-04-05 22:54:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,194 bytes
コンパイル時間 4,461 ms
コンパイル使用メモリ 261,616 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2024-04-05 22:54:11
合計ジャッジ時間 8,996 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 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 33 ms
7,244 KB
testcase_16 AC 37 ms
7,760 KB
testcase_17 AC 24 ms
6,676 KB
testcase_18 AC 37 ms
7,812 KB
testcase_19 AC 31 ms
7,024 KB
testcase_20 AC 22 ms
6,676 KB
testcase_21 AC 37 ms
7,844 KB
testcase_22 AC 28 ms
6,676 KB
testcase_23 AC 25 ms
6,676 KB
testcase_24 AC 21 ms
6,676 KB
testcase_25 AC 39 ms
8,000 KB
testcase_26 AC 38 ms
8,000 KB
testcase_27 AC 39 ms
8,000 KB
testcase_28 AC 39 ms
8,000 KB
testcase_29 AC 39 ms
8,000 KB
testcase_30 AC 39 ms
8,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n;
	cin>>n;
	if(n==1){
		cout<<-1<<endl;
		return 0;
	}
	if(n==2){
		cout<<"1 6 2 4 3 5"<<endl;
		return 0;
	}
	vector<long long> ans(n*3);
	rep(i,n){
		ans[i+n] = i+1;
	}
	long long s0 = 0,s1 = 0;
	rep(i,n){
		long long x = n*3 - i*2;
		long long y = x-1;
		swap(x,y);
		if(s0>=s1)swap(x,y);
		
		ans[n-1-i] = y;
		ans[n*3-1-i] = x;
		s0 += y * (n-i);
		s1 += x * (n-i);
		
		
	}
	if(s0<s1){
		int c=  n*2;
		rep(i,n){
			if(ans[n*2+i]+1==ans[n*2+i+1]){
				s1--;
				swap(ans[n*2+i],ans[n*2+i+1]);
				if(s0==s1)break;
			}
		}
	}
	else if(s1<s0){
		rep(i,n){
			if(ans[i]+1==ans[i+1]){
				s0--;
				swap(ans[i],ans[i+1]);
			}
			if(s0==s1)break;
		}
		
	}/*
	s0 = 0,s1 = 0;
	rep(i,n){
		s0 += ans[i] * ans[i+n];
		s1 += ans[i+n] * ans[i+n*2];
	}
	cout<<s0<<' '<<s1<<endl;
	return 0;
	*/
	rep(i,n*3){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}
0