2 solutions
-
0
Guest MOD
-
0
#include <algorithm> #include <iostream> #include <set> #include <utility> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(2 * N); for (auto& a : A) cin >> a; vector<vector<int>> pos(N + 1); for (int i = 0; i < 2 * N; i++) pos[A[i]].push_back(i); set<pair<int, int>> ans; for (int i = 0; i + 1 < 2 * N; i++) { int a = A[i], b = A[i + 1]; if (pos[a][0] + 1 == pos[a][1]) continue; if (pos[b][0] + 1 == pos[b][1]) continue; vector<int> v{pos[a][0], pos[a][1], pos[b][0],pos[b][1]}; sort(begin(v), end(v)); if (v[0] + 1 == v[1] and v[2] + 1 == v[3]) { if(a > b) swap(a,b); ans.insert({a,b}); } } cout << ans.size() << "\n"; }
- 1
Information
- ID
- 1447
- Time
- 2000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 44
- Accepted
- 11
- Uploaded By