結果

問題 No.2779 Don't make Pair
ユーザー Y.Y.Y.Y.
提出日時 2024-06-07 22:21:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,276 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 123,312 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2024-06-07 22:21:24
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 35 ms
6,940 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 25 ms
6,944 KB
testcase_13 AC 27 ms
6,940 KB
testcase_14 AC 19 ms
6,944 KB
testcase_15 AC 40 ms
6,944 KB
testcase_16 AC 42 ms
6,944 KB
testcase_17 AC 32 ms
6,940 KB
testcase_18 AC 25 ms
6,940 KB
testcase_19 AC 33 ms
6,940 KB
testcase_20 AC 18 ms
6,940 KB
testcase_21 AC 52 ms
7,168 KB
testcase_22 AC 51 ms
7,168 KB
testcase_23 AC 64 ms
8,348 KB
testcase_24 AC 50 ms
7,168 KB
testcase_25 AC 52 ms
7,168 KB
testcase_26 AC 52 ms
7,296 KB
testcase_27 AC 54 ms
7,424 KB
testcase_28 AC 52 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define MAX_LL (1LL<<62)
#define MOD 998244353

ll max(const ll &a, const ll &b) {if(a>b) return a; else return b;}
ll min(const ll &a, const ll &b) {if(a<b) return a; else return b;}
ll calc_gcd(ll a, ll b) {while(true){if(a*b == 0) return a+b; else if(a>b) a %= b; else b %= a;}}
ull pow_mod(ull a, ull b, ull mod=-1) {if(mod<2) return 0; ull ans=1, now=a; while(b>0){if(b%2) ans=(ans*now)%mod; now=(now*now)%mod; b/=2;} return ans;}

bool update_max(ll &a, const ll &b) {if(a<b){a=b; return true;} else return false;}
bool update_max(ld &a, const ld &b) {if(a<b){a=b; return true;} else return false;}
bool update_min(ll &a, const ll &b) {if(a>b){a=b; return true;} else return false;}
bool update_min(ld &a, const ld &b) {if(a>b){a=b; return true;} else return false;}

ll upper_char_to_ll(const char &c) {return ll(c)-65;}

int main() {
  ll N;
  cin >> N;

  vector<ll> A(N);
  for(ll i=0; i<N; i++){
    cin >> A[i];
  }

  vector<pair<ll, ll>> sortedA(N);
  for(ll i=0; i<N; i++){
    sortedA[i] = {A[i], i};
  }
  
  sort(ALL(sortedA));

  for(ll i=2; i<N; i++){
    if(sortedA[i-2].first == sortedA[i-1].first && sortedA[i-1].first == sortedA[i].first){
      cout << 0 << endl << endl;
      return 0;
    }
  }
  
  vector<ll> pair_counts(N);
  ll border = 0;

  for(ll i=1; i<N; i++){
    if(sortedA[i-1].first == sortedA[i].first){
      pair_counts[sortedA[i-1].second]++;
      pair_counts[sortedA[i].second]--;
      border++;
    }
  }

  vector<ll> pair_counts_running_totals(N);
  pair_counts_running_totals[0] = pair_counts[0];
  for(ll i=1; i<N; i++){
    pair_counts_running_totals[i] = pair_counts_running_totals[i-1] + pair_counts[i];
  }

  vector<ll> answers;
  for(ll i=0; i<N-1; i++){
    if(pair_counts_running_totals[i] >= border)
      answers.push_back(i+1);
  }

  cout << answers.size() << endl;
  for(ll i=0; i<answers.size(); i++){
    cout << answers[i];
    if(i != answers.size() - 1){
      cout << " ";
    }
  }
  cout << endl;
  
  return 0;
}
0