結果

問題 No.2779 Don't make Pair
ユーザー VvyLwVvyLw
提出日時 2024-06-07 23:37:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 102,020 KB
実行使用メモリ 12,436 KB
最終ジャッジ日時 2024-12-26 10:50:48
合計ジャッジ時間 3,725 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#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