結果

問題 No.2779 Don't make Pair
コンテスト
ユーザー VvyLw
提出日時 2024-06-07 23:37:38
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 942 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,184 ms
コンパイル使用メモリ 176,220 KB
実行使用メモリ 12,584 KB
最終ジャッジ日時 2026-06-01 08:24:28
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <unordered_map>
template <class T, class U> inline bool chmax(T& a, const U& b){ if(a<b){ a=b; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& a, const U& b){ if(a>b){ a=b; return 1; } return 0; }
int main() {
    int n;
    std::cin >> n;
    std::unordered_map<int, std::vector<int>> m;
    for(int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        m[a].emplace_back(i);
    }
    int l = 0, r = n - 1;
    for(const auto &[k, v]: m) {
        const int x = std::ssize(v);
        if(x > 2) {
            std::cout << "0\n\n";
            return 0;
        } else if(x == 2) {
            chmax(l, v.front());
            chmin(r, v.back());
        }
    }
    if(l < r) {
        std::cout << r - l << '\n';
        for(int i = l; ++i <= r;) {
            std::cout << i << " \n"[i == r];
        }
    } else {
        std::cout << "0\n\n";
    }
}
0