結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2017-08-06 10:43:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,045 bytes |
コンパイル時間 | 802 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 22:43:02 |
合計ジャッジ時間 | 1,666 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 8 WA * 21 |
ソースコード
#include <iostream> #include <queue> #include <vector> #include <cmath> #include <algorithm> #include <map> using namespace std; using ll = long long; const ll INF = 1e9; int main() { int N; cin >> N; int a[N], cnt = 0, cnt1 = 0; for (int i = 0; i < N; i++) { cin >> a[i]; if (a[i] < -1) cnt++; if (a[i] == -1) { cnt++; cnt1++; } } int ans = a[0], rest = cnt - 1; for (int i = 1; i < N; i++) { if (a[i] == 1 || a[i] == 0) { ans += 1; } else if (a[i] <= -1) { rest--; if (rest == 0) { if (ans < 0) ans *= a[i]; else ans -= a[i]; } else { ans *= a[i]; if (ans == 0) ans -= a[i]; } } else { if (rest == 0 && ans < 0) { ans += a[i]; } else { ans *= a[i]; if (ans == 0) ans += a[i]; } } } cout << ans << endl; return 0; }