提出 #64349162


ソースコード 拡げる

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n; cin>>n;
        vector<int> arr(2*n);
        for(int i=0;i<2*n;i++) cin>>arr[i];

        vector<vector<int>> pos(n+1);

        for(int i=0;i<2*n;i++) pos[arr[i]].push_back(i);

        set<pair<int,int>> st;

        for(int i=0;i<2*n-1;i++) {
            if(arr[i] == arr[i+1]) {
                arr[i] = arr[i+1] = -1;
            }
        }

        for(int i=0;i<2*n-1;i++) {
            int a = arr[i], b = arr[i+1];
            if(a == -1 || b == -1) continue;
            int p1 = pos[a][0], p2 = pos[a][1];
            int p3 = pos[b][0], p4 = pos[b][1];

            vector<int> v{p1, p2, p3, p4};
            sort(v.begin(), v.end());

            if(v[0] + 1 == v[1] && v[2] + 1 == v[3]) {
                st.insert(minmax(a, b));
            }
        }

        cout<<st.size()<<endl;
    }
}

提出情報

提出日時
問題 D - Switch Seats
ユーザ sivasaran2003
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1022 Byte
結果 AC
実行時間 168 ms
メモリ 25100 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 19
セット名 テストケース
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 96 ms 3660 KiB
01_small_01.txt AC 96 ms 3444 KiB
01_small_02.txt AC 78 ms 3476 KiB
01_small_03.txt AC 78 ms 3512 KiB
01_small_04.txt AC 79 ms 3516 KiB
01_small_05.txt AC 78 ms 3468 KiB
01_small_06.txt AC 78 ms 3660 KiB
02_random_1_00.txt AC 108 ms 15616 KiB
02_random_1_01.txt AC 107 ms 15664 KiB
02_random_1_02.txt AC 106 ms 15760 KiB
02_random_1_03.txt AC 106 ms 15672 KiB
02_random_1_04.txt AC 107 ms 15596 KiB
03_random_2_00.txt AC 167 ms 22112 KiB
03_random_2_01.txt AC 165 ms 22136 KiB
03_random_2_02.txt AC 168 ms 22212 KiB
04_max_00.txt AC 137 ms 25100 KiB
05_corner_00.txt AC 78 ms 15520 KiB
05_corner_01.txt AC 78 ms 15660 KiB