結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
okchan08
|
| 提出日時 | 2018-04-06 12:15:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,001 bytes |
| コンパイル時間 | 617 ms |
| コンパイル使用メモリ | 60,584 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-26 10:45:17 |
| 合計ジャッジ時間 | 1,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:21: warning: ‘next’ may be used uninitialized in this function [-Wmaybe-uninitialized]
22 | int next;
| ^~~~
ソースコード
#include <iostream>
#include <vector>
#include <string>
using namespace std;
char op[] = {'*', '/', '+', '-'};
int main(){
int N; cin >> N;
vector<int> A(N);
for(int i=0;i<N;i++) cin >> A[i];
int tot_max = A[0];
int tot_min = A[0];
for(int i=1;i<N;i++){
int next_max = -2e9;
int next_min = 2e9;
for(auto cur : {tot_max, tot_min}){
for(int j=0;j<4;j++){
int next;
if(op[j] == '/' && A[i]==0) continue;
switch(op[j]){
case '+' : next = cur + A[i]; break;
case '-' : next = cur - A[i]; break;
case '*' : next = cur * A[i]; break;
case '/' : next = cur / A[i]; break;
}
next_max = max(next_max, next);
next_min = min(next_min, next);
}
}
tot_max = next_max;
tot_min = next_min;
}
cout << tot_max << endl;
return 0;
}
okchan08