結果
問題 | No.1816 MUL-DIV Game |
ユーザー |
![]() |
提出日時 | 2022-01-21 23:01:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 14,603 ms |
コンパイル使用メモリ | 406,464 KB |
最終ジャッジ日時 | 2025-01-27 14:21:51 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <boost/multiprecision/cpp_int.hpp> using Int = boost::multiprecision::cpp_int; int main() { int n; cin>>n; vector<Int> a(n); for (auto& x : a) { cin>>x; } multiset<Int> ms(a.begin(), a.end()); for (int i = 0; i < n-1; ++i) { assert(ms.size() >= 2); if (i & 1) { // Bob's turn auto x1 = *prev(ms.end()); ms.erase(prev(ms.end())); auto x2 = *prev(ms.end()); ms.erase(prev(ms.end())); ms.insert((x2 + x1 - 1)/x1); } else { // Alice's turn auto xl = *ms.begin(); ms.erase(ms.begin()); if (xl > 1) { auto xr = *ms.begin(); ms.erase(ms.begin()); ms.insert(xl*xr); } else { auto xr = *prev(ms.end()); ms.erase(prev(ms.end())); ms.insert(xl*xr); } } } assert(ms.size() == 1); cout << *ms.begin() << endl; }