結果
問題 |
No.505 カードの数式2
|
ユーザー |
![]() |
提出日時 | 2017-04-21 23:15:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,191 bytes |
コンパイル時間 | 1,245 ms |
コンパイル使用メモリ | 54,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 17:41:30 |
合計ジャッジ時間 | 1,612 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:51:9: warning: ‘flag’ may be used uninitialized in this function [-Wmaybe-uninitialized] 51 | if (i == flag) total = total - a[i]; | ^~
ソースコード
#include <iostream> using namespace std; int main(){ int N, a[16]; int cnt=0; int flag; cin >> N; for (int i=0; i<N; i++) cin >> a[i]; int total = a[0]; for (int i=0; i<N; i++){ if (a[i] < 0){ flag = i; break; } } for (int i=0; i<N; i++){ if (a[i] <= -2) cnt++; } cnt = cnt % 2; if (cnt == 0){ for (int i=1; i<N; i++){ if ((a[i] == 0)||(a[i] == 1)){ total = total + a[i]; } else if (a[i] >= 2){ if (total == 0) total = total + a[i]; else total = total * a[i]; } else if (a[i] == -1){ total = total - a[i]; } else { if (total == 0) total = total - a[i]; else total = total * a[i]; } } } else if (cnt == 1){ for (int i=1; i<N; i++){ if ((a[i] == 0)||(a[i] == 1)){ total = total + a[i]; } else if (a[i] >= 2){ if (total == 0) total = total + a[i]; else total = total * a[i]; } else { if ((flag == 0)&&(i == 1)) total = total + a[i]; if (i == flag) total = total - a[i]; else total = total * a[i]; } } } cout << total << endl; return 0; }