結果

問題 No.2779 Don't make Pair
ユーザー kaede2020
提出日時 2024-06-07 22:35:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 8,279 ms
コンパイル使用メモリ 336,320 KB
実行使用メモリ 13,380 KB
最終ジャッジ日時 2024-12-26 08:45:54
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 16 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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;
            return 0;
        }
        if(p.second==2) pair_cnt++;
    }
    vector<int>ans;
    rep(i,n-1){
        if(mp[a[i]]==2&&pair_cnt==1&&mp2[a[i]]==0){
            ans.push_back(i+1);
            pair_cnt--;
        }else if(mp[a[i]]==2&&pair_cnt==2){
            pair_cnt--;
        }else if(mp[a[i]]==1&&pair_cnt==0&&mp2[a[i]]==0){
            ans.push_back(i+1);
        }
        mp[a[i]]--;
        mp2[a[i]]++;
        if(mp2[a[i]]==2) pair_cnt++;
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i] << " ";
    cout<<endl;
    return 0;
}
0