Submission #64295833
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for (int i = (l); i <= (r); i++)
#define per(i,r,l) for (int i = (r); i >= (l); i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define maxn(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod = 998244353;
mt19937 gen(random_device{}());
ll rp(ll a,ll b) {ll res=1%mod;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 400100;
int n;
int a[N];
bool no[N];
set<PII> st;
void solve() {
// init();
scanf("%d", &n);
st.clear();
rep(i,1,n) no[i] = false;
rep(i,1,2 * n) {
scanf("%d", &a[i]);
if (i > 1 && a[i] == a[i - 1]) no[a[i]] = true;
}
int ans = 0;
rep(i,3,2 * n) {
if (a[i] != a[i - 1] && !no[a[i]] && !no[a[i - 1]]) {
if (st.count(mp(a[i], a[i - 1]))) {
ans++;
}
}
if (a[i - 1] != a[i - 2]) {
st.insert(mp(a[i - 1], a[i - 2]));
st.insert(mp(a[i - 2], a[i - 1]));
}
}
printf("%d\n", ans);
}
int main() {
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Switch Seats |
| User |
actor |
| Language |
C++ 20 (gcc 12.2) |
| Score |
400 |
| Code Size |
1354 Byte |
| Status |
AC |
| Exec Time |
397 ms |
| Memory |
43056 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:35:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:55:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d", &T);
| ~~~~~^~~~~~~~~~
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 |
1 ms |
3612 KiB |
| 01_small_00.txt |
AC |
47 ms |
3696 KiB |
| 01_small_01.txt |
AC |
48 ms |
3680 KiB |
| 01_small_02.txt |
AC |
85 ms |
3920 KiB |
| 01_small_03.txt |
AC |
84 ms |
3676 KiB |
| 01_small_04.txt |
AC |
84 ms |
3692 KiB |
| 01_small_05.txt |
AC |
84 ms |
3724 KiB |
| 01_small_06.txt |
AC |
84 ms |
3864 KiB |
| 02_random_1_00.txt |
AC |
397 ms |
42976 KiB |
| 02_random_1_01.txt |
AC |
367 ms |
42984 KiB |
| 02_random_1_02.txt |
AC |
379 ms |
42860 KiB |
| 02_random_1_03.txt |
AC |
379 ms |
42936 KiB |
| 02_random_1_04.txt |
AC |
369 ms |
43056 KiB |
| 03_random_2_00.txt |
AC |
310 ms |
29752 KiB |
| 03_random_2_01.txt |
AC |
317 ms |
29908 KiB |
| 03_random_2_02.txt |
AC |
321 ms |
29864 KiB |
| 04_max_00.txt |
AC |
169 ms |
24420 KiB |
| 05_corner_00.txt |
AC |
101 ms |
24360 KiB |
| 05_corner_01.txt |
AC |
128 ms |
24304 KiB |