Submission #64328743
Source Code Expand
#include <bits/stdc++.h>
using ll = long long;
const int N = 3e5;
void solve() {
ll n;
std::cin >> n;
std::vector<ll> a(2 * n + 10, 0);
for (int i = 1; i <= 2 * n; i++) {
std::cin >> a[i];
}
int cnt = 0;
std::vector<ll> b;
for (int i = 1; i <= 2 * n; i++) {
if (a[i] != a[i - 1] && a[i] != a[i + 1]) {
cnt++;
} else if (cnt != 0) {
b.push_back(cnt);
cnt = 0;
}
}
if (cnt != 0) {
b.push_back(cnt);
} else if (cnt == 0 && b.empty()) {
std::cout << 0 << "\n";
return;
}
if (b.size() == 1) {
std::cout << n - 1 << "\n";
return;
}
std::sort(b.begin(), b.end());
int ans = 0;
int m = b.size();
for (int i = 0; i < m; i += 2) {
if (b[i] % 2 == 0) {
ans += b[i] / 2;
} else {
ans += b[i];
}
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false), std::cout.tie(nullptr), std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Switch Seats |
| User | mellowsky |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1187 Byte |
| Status | WA |
| Exec Time | 22 ms |
| Memory | 7256 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 02_random_1_00.txt, 02_random_1_01.txt, 02_random_1_02.txt, 02_random_1_03.txt, 02_random_1_04.txt, 03_random_2_00.txt, 03_random_2_01.txt, 03_random_2_02.txt, 04_max_00.txt, 05_corner_00.txt, 05_corner_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3400 KiB |
| 01_small_00.txt | WA | 17 ms | 3432 KiB |
| 01_small_01.txt | WA | 17 ms | 3428 KiB |
| 01_small_02.txt | WA | 15 ms | 3664 KiB |
| 01_small_03.txt | WA | 16 ms | 3460 KiB |
| 01_small_04.txt | WA | 16 ms | 3544 KiB |
| 01_small_05.txt | WA | 16 ms | 3404 KiB |
| 01_small_06.txt | WA | 15 ms | 3544 KiB |
| 02_random_1_00.txt | WA | 22 ms | 6300 KiB |
| 02_random_1_01.txt | WA | 22 ms | 6396 KiB |
| 02_random_1_02.txt | WA | 21 ms | 6204 KiB |
| 02_random_1_03.txt | WA | 21 ms | 6384 KiB |
| 02_random_1_04.txt | WA | 21 ms | 6392 KiB |
| 03_random_2_00.txt | WA | 22 ms | 6188 KiB |
| 03_random_2_01.txt | WA | 22 ms | 6228 KiB |
| 03_random_2_02.txt | WA | 22 ms | 6300 KiB |
| 04_max_00.txt | AC | 18 ms | 6236 KiB |
| 05_corner_00.txt | AC | 19 ms | 6400 KiB |
| 05_corner_01.txt | WA | 20 ms | 7256 KiB |