結果

問題 No.1816 MUL-DIV Game
ユーザー tnakao0123
提出日時 2022-01-29 12:50:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 48,104 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2025-01-01 21:59:58
合計ジャッジ時間 2,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:35:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |     scanf("%d", &ai);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1816.cc:  No.1816 MUL-DIV Game - yukicoder
 */

#include<cstdio>
#include<set>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;
typedef multiset<ll> msl;

/* global variables */

msl as;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    as.insert(ai);
  }

  while (as.size() > 1) {
    // Alice
    {
      msl::iterator mit = as.begin();
      ll a0 = *(mit++), a1 = *(mit++);
      as.erase(as.begin(), mit);
      as.insert(a0 * a1);
      if (as.size() == 1) break;
    }

    // Bob
    {
      msl::iterator mit = as.end();
      ll a0 = *(--mit), a1 = *(--mit);
      as.erase(mit, as.end());
      as.insert(1);
      if (as.size() == 1) break;
    }
  }

  printf("%lld\n", *as.begin());
  return 0;
}
0