結果

問題 No.2779 Don't make Pair
ユーザー elphe
提出日時 2024-07-16 19:25:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 81,348 KB
最終ジャッジ日時 2025-02-23 15:51:56
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, A, i, l, r;
    set<int> paired;
    map<int, int> odd;
    map<int, int>::iterator itr;
    cin >> N;
    l = 0, r = N - 1;
    for (i = 0; i != N; ++i)
    {
        cin >> A;
        if (paired.find(A) != paired.end())
            r = 0;
        else if ((itr = odd.find(A)) != odd.end())
        {
            if (l < itr->second) l = itr->second;
            if (r > i) r = i;
            paired.insert(itr->first);
            odd.erase(itr);
        }
        else
            odd.insert({ A, i });
    }

    if (l < r)
    {
        cout << r - l << '\n' << l + 1;
        for (++l; l != r; ++l)
            cout << ' ' << l + 1;
        cout << '\n';
    }
    else
        cout << "0\n\n";

    return 0;
}
0