結果

問題 No.2779 Don't make Pair
ユーザー yuusaanyuusaan
提出日時 2024-05-29 08:20:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 255,184 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-06-06 22:55:12
合計ジャッジ時間 5,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 34 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 53 ms
7,936 KB
testcase_13 AC 57 ms
8,192 KB
testcase_14 AC 39 ms
6,400 KB
testcase_15 AC 91 ms
10,632 KB
testcase_16 AC 100 ms
11,276 KB
testcase_17 AC 67 ms
8,832 KB
testcase_18 AC 52 ms
7,424 KB
testcase_19 AC 75 ms
9,472 KB
testcase_20 AC 37 ms
6,528 KB
testcase_21 AC 130 ms
12,928 KB
testcase_22 AC 130 ms
13,056 KB
testcase_23 AC 135 ms
13,056 KB
testcase_24 AC 128 ms
12,928 KB
testcase_25 AC 128 ms
13,056 KB
testcase_26 AC 131 ms
12,928 KB
testcase_27 AC 127 ms
13,056 KB
testcase_28 AC 131 ms
12,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int j = 0; j < n; j++)cin >> a[j];
    map<int,int> counts;//ある要素が何個含まれているかのカウント
    map<int,int> loc;//要素のうち一番左のものの位置
    vector<int> l(0),r(0);
    for(int j = 0; j < n; j++){
        counts[a[j]]++;
        if(counts[a[j]] == 1){
            loc[a[j]] = j;
        }
        else if(counts[a[j]] == 2){
            l.push_back(loc[a[j]]);
            r.push_back(j);
        }
        else{
            //同じ要素が3つ含まれているなら条件を満たすjは存在しない
            cout << 0 << endl;
            cout << endl;
            return 0;
        }
    }
    int m = l.size();
    int L = 0,R = n-1;
    for(int j = 0; j < m; j++){
        L = max(L,l[j]);
        R = min(R,r[j]);
    }
    if(L > R){
        cout << 0 << endl;
        cout << endl;
        return 0;
    }
    else{
        cout << R - L  << endl;
        for(int j = L; j < R; j++){
            cout << j + 1 <<  " ";
        }
        cout << endl;
        return 0;
    }
    return 0;
}
0