結果

問題 No.2732 Similar Permutations
ユーザー 沙耶花沙耶花
提出日時 2024-04-19 21:50:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 2,115 bytes
コンパイル時間 4,495 ms
コンパイル使用メモリ 267,748 KB
実行使用メモリ 17,396 KB
最終ジャッジ日時 2024-04-19 21:51:11
合計ジャッジ時間 23,426 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 42 ms
7,424 KB
testcase_03 AC 80 ms
10,880 KB
testcase_04 AC 24 ms
6,940 KB
testcase_05 AC 19 ms
6,944 KB
testcase_06 AC 9 ms
6,940 KB
testcase_07 AC 58 ms
8,960 KB
testcase_08 AC 29 ms
6,944 KB
testcase_09 AC 15 ms
6,944 KB
testcase_10 AC 147 ms
16,256 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 144 ms
16,936 KB
testcase_13 AC 146 ms
16,940 KB
testcase_14 AC 148 ms
16,940 KB
testcase_15 AC 151 ms
17,068 KB
testcase_16 AC 106 ms
13,412 KB
testcase_17 AC 103 ms
13,220 KB
testcase_18 AC 141 ms
15,940 KB
testcase_19 AC 148 ms
16,484 KB
testcase_20 AC 149 ms
16,348 KB
testcase_21 AC 145 ms
17,372 KB
testcase_22 AC 86 ms
11,100 KB
testcase_23 AC 151 ms
17,368 KB
testcase_24 AC 82 ms
11,284 KB
testcase_25 AC 148 ms
17,372 KB
testcase_26 AC 122 ms
15,184 KB
testcase_27 AC 147 ms
17,368 KB
testcase_28 AC 115 ms
14,640 KB
testcase_29 AC 149 ms
17,368 KB
testcase_30 AC 106 ms
13,816 KB
testcase_31 AC 147 ms
17,372 KB
testcase_32 AC 136 ms
16,412 KB
testcase_33 AC 146 ms
17,372 KB
testcase_34 AC 96 ms
12,112 KB
testcase_35 AC 152 ms
17,240 KB
testcase_36 AC 139 ms
16,292 KB
testcase_37 AC 149 ms
17,396 KB
testcase_38 AC 129 ms
15,732 KB
testcase_39 AC 145 ms
17,244 KB
testcase_40 AC 123 ms
15,192 KB
testcase_41 AC 146 ms
17,372 KB
testcase_42 AC 109 ms
14,232 KB
testcase_43 AC 146 ms
17,244 KB
testcase_44 AC 74 ms
10,596 KB
testcase_45 AC 144 ms
17,244 KB
testcase_46 AC 133 ms
16,016 KB
testcase_47 AC 140 ms
17,248 KB
testcase_48 AC 86 ms
11,692 KB
testcase_49 AC 141 ms
17,248 KB
testcase_50 AC 82 ms
11,680 KB
testcase_51 AC 128 ms
17,244 KB
testcase_52 AC 113 ms
15,588 KB
testcase_53 AC 142 ms
16,492 KB
testcase_54 AC 144 ms
16,512 KB
testcase_55 AC 143 ms
16,564 KB
testcase_56 AC 145 ms
16,496 KB
testcase_57 AC 72 ms
10,112 KB
testcase_58 AC 98 ms
12,672 KB
testcase_59 AC 94 ms
12,132 KB
testcase_60 AC 82 ms
10,624 KB
testcase_61 AC 71 ms
9,984 KB
testcase_62 AC 123 ms
14,440 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
testcase_65 AC 1 ms
5,376 KB
testcase_66 AC 1 ms
5,376 KB
testcase_67 AC 1 ms
5,376 KB
testcase_68 AC 1 ms
5,376 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 2 ms
5,376 KB
testcase_71 AC 2 ms
5,376 KB
testcase_72 AC 1 ms
5,376 KB
testcase_73 AC 2 ms
5,376 KB
testcase_74 AC 2 ms
5,376 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 1 ms
5,376 KB
testcase_78 AC 1 ms
5,376 KB
testcase_79 AC 1 ms
5,376 KB
testcase_80 AC 2 ms
5,376 KB
testcase_81 AC 1 ms
5,376 KB
testcase_82 AC 2 ms
5,376 KB
testcase_83 AC 1 ms
5,376 KB
testcase_84 AC 1 ms
5,376 KB
testcase_85 AC 1 ms
5,376 KB
testcase_86 AC 1 ms
5,376 KB
testcase_87 AC 1 ms
5,376 KB
testcase_88 AC 1 ms
5,376 KB
testcase_89 AC 1 ms
5,376 KB
testcase_90 AC 2 ms
5,376 KB
testcase_91 AC 1 ms
5,376 KB
testcase_92 AC 2 ms
5,376 KB
testcase_93 AC 1 ms
5,376 KB
testcase_94 AC 1 ms
5,376 KB
testcase_95 AC 2 ms
5,376 KB
testcase_96 AC 1 ms
5,376 KB
testcase_97 AC 2 ms
5,376 KB
testcase_98 AC 1 ms
5,376 KB
testcase_99 AC 2 ms
5,376 KB
testcase_100 AC 2 ms
5,376 KB
testcase_101 AC 2 ms
5,376 KB
testcase_102 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
void Out(vector<int> p){
	rep(i,p.size()){
		if(i!=0)cout<<' ';
		cout<<p[i];
	}
	cout<<endl;
}
int main(){
	
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	if(n<=8){
		vector<int> p(n);
		rep(i,n)p[i] = i+1;
		map<int,vector<int>> mp;
		do{
			int s = 0;
			rep(i,n)s ^= a[i] + p[i];
			if(mp.count(s)){
				Out(p);
				Out(mp[s]);
				return 0;
			}
			else mp[s] = p;
		}
		while(next_permutation(p.begin(),p.end()));
		cout<<-1<<endl;
	}
	else{
		rep(i,n)a[i] ++;
		vector<vector<int>> is(4);
		rep(i,n)is[a[i]%4].push_back(i);
		vector<int> p(n,-1),q(n,-1);
		set<int> s;
		rep(i,n)s.insert(i);
		if(is[0].size() + is[2].size()>=2){
			vector<int> t;
			rep(i,is[0].size())t.push_back(is[0][i]);
			rep(i,is[2].size())t.push_back(is[2][i]);
			while(t.size()>=3)t.pop_back();
			p[t[0]] = 0;
			p[t[1]] = 1;
			s.erase(0);
			s.erase(1);
			rep(i,n){
				if(p[i]==-1){
					p[i] = *s.begin();
					s.erase(s.begin());
				}
			}
			q = p;
			swap(q[t[0]],q[t[1]]);
			rep(i,n){
				p[i]++,q[i]++;
			}
			Out(p);
			Out(q);
			
		}
		else if(is[0].size() + is[1].size()>=2){
			vector<int> t;
			rep(i,is[0].size())t.push_back(is[0][i]);
			rep(i,is[1].size())t.push_back(is[1][i]);
			while(t.size()>=3)t.pop_back();
			p[t[0]] = 0;
			p[t[1]] = 2;
			s.erase(0);
			s.erase(2);
			rep(i,n){
				if(p[i]==-1){
					p[i] = *s.begin();
					s.erase(s.begin());
				}
			}
			q = p;
			swap(q[t[0]],q[t[1]]);
			rep(i,n){
				p[i]++,q[i]++;
			}
			Out(p);
			Out(q);
			
		}
		else{
			vector<int> t;
			rep(i,is[3].size())t.push_back(is[3][i]);
			while(t.size()>=3)t.pop_back();
			p[t[0]] = 1;
			p[t[1]] = 3;
			s.erase(1);
			s.erase(3);
			rep(i,n){
				if(p[i]==-1){
					p[i] = *s.begin();
					s.erase(s.begin());
				}
			}
			q = p;
			swap(q[t[0]],q[t[1]]);
			rep(i,n){
				p[i]++,q[i]++;
			}
			Out(p);
			Out(q);
		}
		
	}
	return 0;
}
0