結果
| 問題 |
No.2732 Similar Permutations
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-04-05 15:05:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,688 bytes |
| コンパイル時間 | 3,658 ms |
| コンパイル使用メモリ | 252,712 KB |
| 実行使用メモリ | 9,700 KB |
| 最終ジャッジ日時 | 2024-10-01 01:10:21 |
| 合計ジャッジ時間 | 17,864 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 101 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> inline bool chmin(T &a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
if(n<=2){
if(((a[0]+1)^(a[1]+2))==((a[0]+2)^(a[1]+1))){
cout << "1 2\n";
cout << "2 1\n";
}else{
cout << "-1\n";
}
return 0;
}
vector<ll> o,e;
rep(i,n){
if(a[i]&1) o.push_back(i);
else e.push_back(i);
}
vector<ll> p(n),q(n);
if(2<=(ll)o.size()){
ll now=3;
rep(i,n){
if(i==o[0]){
p[i]=1;
}else if(i==o[1]){
p[i]=2;
}else{
p[i]=now;
now++;
}
}
q=p;
swap(q[o[0]],q[o[1]]);
}else{
ll now=1;
rep(i,n){
if(i==e[0]){
p[i]=2;
}else if(i==e[1]){
p[i]=3;
}else{
p[i]=now;
if(now==1) now=4;
else now++;
}
}
q=p;
swap(q[e[0]],q[e[1]]);
}
rep(i,n) cout << p[i] << ' ';
cout << '\n';
rep(i,n) cout << q[i] << ' ';
cout << '\n';
}
FplusFplusF