結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-29 17:06:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,652 bytes |
| コンパイル時間 | 952 ms |
| コンパイル使用メモリ | 84,728 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-10 19:25:49 |
| 合計ジャッジ時間 | 1,787 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:78:14: warning: ‘ope’ may be used uninitialized in this function [-Wmaybe-uninitialized]
78 | else if (ope == '+')mi = mi + stoll(num1);
| ^~
ソースコード
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;
int s[50];
int main()
{
int N,pl=0,min=0;
cin >> N;
int j = 0,k =0;
for (int i = 0; i < N; i++) {
char c; cin >> c;
if (c >= '0' && c <= '9')
s[j++] = c-'0';
else {
if (c == '+')pl++;
else min++;
}
}
sort(s, s + j);
reverse(s+1,s+j);
ll mi = s[0], sum = pl + min,sum1;
int min_t = min, pl_t = pl;
sum1 = sum;
string num1 = "";
char ope;
for (int i = 1; i < j; i++) {
if (sum != 0) {
if (min != 0) {
ope = '-';
min--;
}
else if (pl != 0) {
ope = '+';
pl--;
}
sum--;
}
num1 += to_string(s[i]);
if (sum != 0) {
if (ope == '-') {
mi = mi - stoll(num1);
}
else if (ope == '+')
mi = mi + stoll(num1);
num1 = ' ';
}
}
if (ope == '-')mi = mi - stoll(num1);
else if (ope == '+')mi = mi + stoll(num1);
sort(s, s + j);
reverse(s, s+j);
ll mx = 0;
num1 = ' ';
ope = '+';
for (int i = 0; i < j; i++) {
if (j - (i + 1) <sum1) {
if (pl_t != 0) {
ope = '+';
pl_t--;
}
else {
ope = '-';
}
}
num1 += to_string(s[i]);
if (j - (i + 1) <= sum1) {
if (ope == '-')
mx = mx - stoll(num1);
else
mx = mx + stoll(num1);
num1 = ' ';
}
}
cout << mx << " " << mi << endl;
return 0;
}