提出 #29744675
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define SET(a) memset(a, -1, sizeof a)
#define R(i, a, b) for (int i = (a); i < (b); ++i)
#define L(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using i64 = long long;
constexpr int xn = 5001;
int n, a[xn], b[xn];
void push(int p) { int x = a[p - 2], y = a[p - 1], z = a[p]; a[p - 2] = z; a[p - 1] = x; a[p] = y; }
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
R(i, 0, n) cin >> a[i]; R(i, 0, n) cin >> b[i];
vector<int> _a(a, a + n), _b(b, b + n);
sort(_a.begin(), _a.end()); sort(_b.begin(), _b.end());
if (_a != _b) { cout << "No\n"; return 0; }
R(i, 0, n - 1) if (a[i] == a[i + 1]) { cout << "Yes\n"; return 0; }
R(i, 0, n - 2) {
int p = -1; R(j, i, n) if (a[j] == b[i]) p = j;
for (; p > i; --p) if (p < n - 1) { push(p + 1); push(p + 1); } else { push(p); push(p); }
assert(a[i] == b[i]);
// cerr << "a = "; R(j, 0, n) cerr << a[j] << ' '; cerr << '\n'; // @
}
if (a[n - 2] == b[n - 2] and a[n - 1] == b[n - 1]) cout << "Yes\n";
else cout << "No\n";
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Triple Shift |
| ユーザ | LMENSHKORG |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 400 |
| コード長 | 1105 Byte |
| 結果 | AC |
| 実行時間 | 34 ms |
| メモリ | 3732 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 7 ms | 3620 KiB |
| 00-sample-002.txt | AC | 2 ms | 3488 KiB |
| 00-sample-003.txt | AC | 3 ms | 3576 KiB |
| 01-001.txt | AC | 3 ms | 3676 KiB |
| 01-002.txt | AC | 4 ms | 3584 KiB |
| 01-003.txt | AC | 4 ms | 3560 KiB |
| 01-004.txt | AC | 2 ms | 3612 KiB |
| 01-005.txt | AC | 2 ms | 3576 KiB |
| 01-006.txt | AC | 4 ms | 3588 KiB |
| 01-007.txt | AC | 2 ms | 3512 KiB |
| 01-008.txt | AC | 4 ms | 3540 KiB |
| 01-009.txt | AC | 3 ms | 3684 KiB |
| 01-010.txt | AC | 5 ms | 3620 KiB |
| 01-011.txt | AC | 16 ms | 3532 KiB |
| 01-012.txt | AC | 7 ms | 3524 KiB |
| 01-013.txt | AC | 33 ms | 3572 KiB |
| 01-014.txt | AC | 17 ms | 3548 KiB |
| 01-015.txt | AC | 6 ms | 3600 KiB |
| 01-016.txt | AC | 28 ms | 3692 KiB |
| 01-017.txt | AC | 4 ms | 3504 KiB |
| 01-018.txt | AC | 2 ms | 3564 KiB |
| 01-019.txt | AC | 27 ms | 3692 KiB |
| 01-020.txt | AC | 4 ms | 3636 KiB |
| 01-021.txt | AC | 5 ms | 3564 KiB |
| 01-022.txt | AC | 4 ms | 3648 KiB |
| 01-023.txt | AC | 4 ms | 3732 KiB |
| 01-024.txt | AC | 5 ms | 3512 KiB |
| 01-025.txt | AC | 3 ms | 3692 KiB |
| 01-026.txt | AC | 5 ms | 3672 KiB |
| 01-027.txt | AC | 5 ms | 3576 KiB |
| 01-028.txt | AC | 7 ms | 3692 KiB |
| 01-029.txt | AC | 4 ms | 3632 KiB |
| 01-030.txt | AC | 4 ms | 3672 KiB |
| 01-031.txt | AC | 34 ms | 3648 KiB |
| 01-032.txt | AC | 31 ms | 3648 KiB |
| 01-033.txt | AC | 30 ms | 3572 KiB |
| 01-034.txt | AC | 31 ms | 3688 KiB |
| 01-035.txt | AC | 30 ms | 3628 KiB |
| 01-036.txt | AC | 33 ms | 3564 KiB |
| 01-037.txt | AC | 34 ms | 3716 KiB |
| 01-038.txt | AC | 32 ms | 3648 KiB |
| 01-039.txt | AC | 32 ms | 3648 KiB |
| 01-040.txt | AC | 31 ms | 3560 KiB |