結果
問題 | No.2732 Similar Permutations |
ユーザー |
👑 ![]() |
提出日時 | 2024-03-27 02:48:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 205 ms / 2,000 ms |
コード長 | 2,101 bytes |
コンパイル時間 | 781 ms |
コンパイル使用メモリ | 74,000 KB |
最終ジャッジ日時 | 2025-02-20 13:58:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 101 |
ソースコード
#include <iostream>#include <vector>using namespace std;int main() {int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++) {cin >> A[i];}if (N == 1) {cout << -1 << endl;return 0;} else if (N == 2) {if (((A[0] + 1) ^ (A[1] + 2)) == ((A[0] + 2) ^ (A[1] + 1))) {cout << 1 << " " << 2 << endl;cout << 2 << " " << 1 << endl;} else {cout << -1 << endl;}return 0;}vector<int> P1(N, -1);vector<int> P2(N, -1);int o_idx1 = -1;int o_idx2 = -1;int e_idx1 = -1;int e_idx2 = -1;for (int i = 0; i < N; i++) {if (A[i] % 2 == 0) {if (e_idx1 == -1) {e_idx1 = i;} else {e_idx2 = i;}} else {if (o_idx1 == -1) {o_idx1 = i;} else {o_idx2 = i;}}}if (o_idx2 != -1) {P1[o_idx1] = 1;P2[o_idx1] = 2;P1[o_idx2] = 2;P2[o_idx2] = 1;int now = 3;for (int i = 0; i < N; i++) {if (i == o_idx1 || i == o_idx2) {continue;} else {P1[i] = now;P2[i] = now;now++;}}} else {P1[e_idx1] = 2;P2[e_idx1] = 3;P1[e_idx2] = 3;P2[e_idx2] = 2;int now = 1;for (int i = 0; i < N; i++) {if (i == e_idx1 || i == e_idx2) {continue;} else {P1[i] = now;P2[i] = now;now++;if (now == 2) {now += 2;}}}}for (int i = 0; i < N; i++) {cout << P1[i];if (i < N - 1) {cout << " ";}}cout << endl;for (int i = 0; i < N; i++) {cout << P2[i];if (i < N - 1) {cout << " ";}}cout << endl;}