結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
Kmcode1
|
| 提出日時 | 2017-04-21 22:50:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 714 bytes |
| コンパイル時間 | 2,205 ms |
| コンパイル使用メモリ | 161,504 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-20 06:24:45 |
| 合計ジャッジ時間 | 3,298 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define MAX 16
vector<int> v;
int main(){
int way = 1;
int n;
cin >> n;
for (int i = 0; i < n; i++){
int a;
scanf("%d", &a);
v.push_back(a);
}
int bet = n - 1;
for (int i = 0; i < bet; i++){
way *= 2;
}
long long int ans = LLONG_MIN;
for (int i = 0; i < way; i++){
long long int sum = v[0];
int x = i;
for (int j = 0; j < bet; j++,x/=2){
if (x % 2 == 0){
if (sum < 0){
sum -= abs(v[j + 1]);
}
else{
sum += abs(v[j + 1]);
}
continue;
}
if (x % 2 == 1){
sum *= v[j+1];
continue;
}
}
ans = max(ans, sum);
}
printf("%lld\n", ans);
return 0;
}
Kmcode1