提出 #64334817
ソースコード 拡げる
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define M 1000000007
#define all(x) x.begin(), x.end()
int ceil(int a, int b)
{
if (a%b) return (a/b)+1;
else return a/b;
}
void solve()
{
ll n;
cin>>n;
vector<ll> v(2*n+1);
vector<ll> first(n+1,-1),last(n+1,-1);
for(int i=1;i<=2*n;i++){
cin>>v[i];
if(first[v[i]]==-1)first[v[i]]=i;
else last[v[i]]=i;
}
vector<vector<ll>> c;
for(int i=1;i<=n;i++){
if(first[i]+1==last[i])continue;
c.push_back({first[i],last[i],i});
}
sort(all(c),[](auto &x, auto &y){
return x[0]<y[0];
});
ll ans=0;
ll sz=c.size();
for(int i=0;i+1<sz;i++){
if(c[i+1][0]==c[i][0]+1 and (c[i+1][1]==c[i][1]+1 or c[i+1][1]==c[i][1]-1)){
ans++;
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Switch Seats |
| ユーザ | dotniiko |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 400 |
| コード長 | 1075 Byte |
| 結果 | AC |
| 実行時間 | 73 ms |
| メモリ | 20472 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3564 KiB |
| 01_small_00.txt | AC | 64 ms | 3512 KiB |
| 01_small_01.txt | AC | 64 ms | 3504 KiB |
| 01_small_02.txt | AC | 45 ms | 3428 KiB |
| 01_small_03.txt | AC | 46 ms | 3376 KiB |
| 01_small_04.txt | AC | 46 ms | 3372 KiB |
| 01_small_05.txt | AC | 46 ms | 3516 KiB |
| 01_small_06.txt | AC | 45 ms | 3576 KiB |
| 02_random_1_00.txt | AC | 71 ms | 20464 KiB |
| 02_random_1_01.txt | AC | 72 ms | 20464 KiB |
| 02_random_1_02.txt | AC | 73 ms | 20412 KiB |
| 02_random_1_03.txt | AC | 73 ms | 20368 KiB |
| 02_random_1_04.txt | AC | 66 ms | 20472 KiB |
| 03_random_2_00.txt | AC | 70 ms | 20316 KiB |
| 03_random_2_01.txt | AC | 66 ms | 20392 KiB |
| 03_random_2_02.txt | AC | 66 ms | 20316 KiB |
| 04_max_00.txt | AC | 34 ms | 20308 KiB |
| 05_corner_00.txt | AC | 20 ms | 9424 KiB |
| 05_corner_01.txt | AC | 26 ms | 14848 KiB |