結果
| 問題 | No.2779 Don't make Pair |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-29 08:20:11 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 2,000 ms |
| コード長 | 1,169 bytes |
| 記録 | |
| コンパイル時間 | 3,184 ms |
| コンパイル使用メモリ | 254,252 KB |
| 実行使用メモリ | 12,956 KB |
| 最終ジャッジ日時 | 2024-12-24 17:47:59 |
| 合計ジャッジ時間 | 6,521 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int j = 0; j < n; j++)cin >> a[j];
map<int,int> counts;//ある要素が何個含まれているかのカウント
map<int,int> loc;//要素のうち一番左のものの位置
vector<int> l(0),r(0);
for(int j = 0; j < n; j++){
counts[a[j]]++;
if(counts[a[j]] == 1){
loc[a[j]] = j;
}
else if(counts[a[j]] == 2){
l.push_back(loc[a[j]]);
r.push_back(j);
}
else{
//同じ要素が3つ含まれているなら条件を満たすjは存在しない
cout << 0 << endl;
cout << endl;
return 0;
}
}
int m = l.size();
int L = 0,R = n-1;
for(int j = 0; j < m; j++){
L = max(L,l[j]);
R = min(R,r[j]);
}
if(L > R){
cout << 0 << endl;
cout << endl;
return 0;
}
else{
cout << R - L << endl;
for(int j = L; j < R; j++){
cout << j + 1 << " ";
}
cout << endl;
return 0;
}
return 0;
}