結果

問題 No.1816 MUL-DIV Game
ユーザー bokusunny
提出日時 2022-01-21 21:30:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 201,144 KB
最終ジャッジ日時 2025-01-27 13:26:30
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr);

void solve() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  multiset<long long> st(A.begin(), A.end());
  int turn = 0;
  while ((int)st.size() > 1) {
    if (turn) {
      auto y = *st.rbegin();
      auto x = *next(st.rbegin());
      st.erase(st.find(y));
      st.erase(st.find(x));
      st.insert((x + y - 1) / y);
    } else {
      auto x = *st.begin();
      auto y = *next(st.begin());
      st.erase(st.find(x));
      st.erase(st.find(y));
      st.insert(x * y);
    }
    turn ^= 1;
  }

  cout << *st.begin() << endl;
}

int main() {
  bokusunny;
  solve();

  return 0;
}
0