結果

問題 No.2732 Similar Permutations
ユーザー GGanari
提出日時 2024-04-19 22:49:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 205,692 KB
最終ジャッジ日時 2025-02-21 05:04:44
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 101
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 998244353LL
#define MAX 1005
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> p(n);
vector<int> pos[4];
for(int i = 0; i<n; i++)
{
int x;
cin >> x;
p[i] = x;
pos[x&3].push_back(i);
}
if(n <= 4)
{
map<int, vector<int>> mp;
vector<int> arr;
for(int i = 1; i<=n; i++)
arr.push_back(i);
do
{
int x = 0;
for(int i = 0; i<n; i++)
x^=(arr[i]+p[i]);
if(mp.count(x))
{
for(int i = 0; i<n; i++)
{
cout << mp[x][i] << " ";
}
cout << "\n";
for(int i = 0; i<n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
mp[x] = arr;
} while (next_permutation(all(arr)));
cout << "-1\n";
return 0;
}
int a = 1;
int b = 2;
int c = 3;
int res1 = 0;
int res2 = 0;
if(pos[0].size() > 1)
{
res1 = pos[0][0];
res2 = pos[0][1];
}
else if(pos[1].size() > 1)
{
res1 = pos[1][0];
res2 = pos[1][1];
}
else if(pos[2].size() > 1)
{
res1 = pos[2][0];
res2 = pos[2][1];
a = 3;
c = 1;
}
else if(pos[3].size() > 1)
{
res1 = pos[3][0];
res2 = pos[3][1];
}
int index = 4;
for(int i = 0; i<n; i++)
{
if(index > n)
index = c;
if(i == res1)
cout << a << " ";
else if(i == res2)
cout << b << " ";
else
{
cout << index << " ";
index++;
}
}
cout << "\n";
index = 4;
for(int i = 0; i<n; i++)
{
if(index > n)
index = c;
if(i == res1)
cout << b << " ";
else if(i == res2)
cout << a << " ";
else
{
cout << index << " ";
index++;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0