結果

問題 No.1816 MUL-DIV Game
ユーザー square1001square1001
提出日時 2022-01-21 21:27:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 78,516 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-08-17 04:56:42
合計ジャッジ時間 2,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 18 ms
4,376 KB
testcase_11 AC 16 ms
4,380 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 47 ms
6,264 KB
testcase_14 AC 24 ms
5,028 KB
testcase_15 AC 32 ms
5,468 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 64 ms
7,324 KB
testcase_18 AC 62 ms
7,296 KB
testcase_19 AC 29 ms
5,180 KB
testcase_20 AC 69 ms
7,336 KB
testcase_21 AC 22 ms
4,852 KB
testcase_22 AC 17 ms
4,660 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 81 ms
8,044 KB
testcase_26 AC 38 ms
4,380 KB
testcase_27 AC 82 ms
8,048 KB
testcase_28 AC 38 ms
4,376 KB
testcase_29 AC 84 ms
8,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (N % 2 == 1) {
		cout << (N == 1 ? A[0] : 1) << endl;
	}
	else {
		multiset<long long> s(A.begin(), A.end());
		for (int i = 0; i < N - 1; i++) {
			if (i % 2 == 0) {
				long long pa = *s.begin(); s.erase(s.begin());
				long long pb = *s.begin(); s.erase(s.begin());
				s.insert(pa * pb);
			}
			else {
				long long pa = *(--s.end()); s.erase(--s.end());
				long long pb = *(--s.end()); s.erase(--s.end());
				s.insert(1);
			}
		}
		cout << *s.begin() << endl;
	}
	return 0;
}
0