結果
問題 |
No.505 カードの数式2
|
ユーザー |
|
提出日時 | 2018-10-25 22:41:00 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 694 bytes |
コンパイル時間 | 277 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-19 05:54:09 |
合計ジャッジ時間 | 1,076 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 4 WA * 25 |
ソースコード
#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; }