Submission #64302308
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int A[400000];
vector<int> idx[200001];
map<pair<int, int>, int> m;
void solve() {
cin >> N;
for (int i = 1; i <= N; ++i) idx[i].clear();
m.clear();
for (int i = 0; i < 2 * N; ++i) {
cin >> A[i];
idx[A[i]].push_back(i);
}
int ans = 0;
for (int i = 0; i + 1 < 2 * N; ++i) {
// i, i + 1
if (A[i] == A[i + 1]) continue;
int a = A[i], b = A[i + 1];
if (idx[a][0] + 1 == idx[a][1]) continue;
if (idx[b][0] + 1 == idx[b][1]) continue;
int aa, bb;
for (auto j: idx[a]) if (j != i) aa = j;
for (auto j: idx[b]) if (j != i + 1) bb = j;
if (abs(aa - bb) == 1) {
if (a > b) swap(a, b);
if (m[{a, b}] == 0) {
++ans;
m[{a, b}] = 1;
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Switch Seats |
| User | danielhO9 |
| Language | C++ 17 (gcc 12.2) |
| Score | 400 |
| Code Size | 1070 Byte |
| Status | AC |
| Exec Time | 135 ms |
| Memory | 28528 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:28:20: warning: ‘bb’ may be used uninitialized [-Wmaybe-uninitialized]
28 | if (abs(aa - bb) == 1) {
| ~~~^~~~
Main.cpp:25:17: note: ‘bb’ was declared here
25 | int aa, bb;
| ^~
Main.cpp:28:20: warning: ‘aa’ may be used uninitialized [-Wmaybe-uninitialized]
28 | if (abs(aa - bb) == 1) {
| ~~~^~~~
Main.cpp:25:13: note: ‘aa’ was declared here
25 | int aa, bb;
| ^~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 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 | 3 ms | 8220 KiB |
| 01_small_00.txt | AC | 21 ms | 8164 KiB |
| 01_small_01.txt | AC | 20 ms | 8232 KiB |
| 01_small_02.txt | AC | 19 ms | 8224 KiB |
| 01_small_03.txt | AC | 19 ms | 8188 KiB |
| 01_small_04.txt | AC | 19 ms | 8288 KiB |
| 01_small_05.txt | AC | 19 ms | 8228 KiB |
| 01_small_06.txt | AC | 19 ms | 8160 KiB |
| 02_random_1_00.txt | AC | 52 ms | 16028 KiB |
| 02_random_1_01.txt | AC | 52 ms | 15984 KiB |
| 02_random_1_02.txt | AC | 51 ms | 16148 KiB |
| 02_random_1_03.txt | AC | 52 ms | 16004 KiB |
| 02_random_1_04.txt | AC | 51 ms | 15988 KiB |
| 03_random_2_00.txt | AC | 135 ms | 24832 KiB |
| 03_random_2_01.txt | AC | 134 ms | 24824 KiB |
| 03_random_2_02.txt | AC | 132 ms | 24708 KiB |
| 04_max_00.txt | AC | 102 ms | 28528 KiB |
| 05_corner_00.txt | AC | 30 ms | 15956 KiB |
| 05_corner_01.txt | AC | 31 ms | 15984 KiB |