結果

問題 No.2779 Don't make Pair
ユーザー kaede2020
提出日時 2024-06-08 06:54:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 6,361 ms
コンパイル使用メモリ 336,880 KB
実行使用メモリ 13,252 KB
最終ジャッジ日時 2024-12-27 04:23:31
合計ジャッジ時間 9,876 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using mint = modint998244353;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};

int n;
int main(){
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int>mp,mp2;
    rep(i,n) mp[a[i]]++;
    int pair_cnt=0;
    for(auto p:mp){
        if(p.second>2){
            cout << 0 << endl;
            cout << " "<< endl;
            return 0;
        }
        if(p.second==2) pair_cnt++;
    }
    vector<int>ans;
    rep(i,n-1){
        if(mp[a[i]]==2)pair_cnt--;
        mp[a[i]]--;
        mp2[a[i]]++;
        if(mp2[a[i]]==2) pair_cnt++;
        if(pair_cnt==0){
            ans.push_back(i+1);
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i] << " ";
    cout<<endl;
    return 0;
}
0