結果

問題 No.505 カードの数式2
コンテスト
ユーザー Mcpu3
提出日時 2018-10-25 22:41:00
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 694 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 220 ms
コンパイル使用メモリ 39,876 KB
最終ジャッジ日時 2026-02-22 02:02:51
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 4 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>

void push(int a, int *top, int stack[])
{
	stack[*top] = a;
	++*top;
}

int compare(const void *x, const void *y)
{
	return *(int*)y - *(int*)x;
}

int main(void)
{
	int N, a, top = 0, stack[16], ans = 0, tmp = 1, i;
	scanf("%d", &N);
	for (i = 0; i < N; ++i) {
		scanf("%d", &a);
		if (a < -1) push(a, &top, stack);
		else if (a + ans > a * ans) ans += a;
		else ans *= a;
	}
	qsort(stack, top, sizeof(int), compare);
	if (top % 2) {
		for (i = 0; i < top - 1; ++i) tmp *= stack[i];
	}
	else {
		for (i = 0; i < top; ++i) tmp *= stack[i];
	}
	if (ans > 1) ans *= tmp;
	else ans += tmp;
	printf("%d", ans);
	return 0;
}
0