竞赛讨论区 > 为什么把比赛wa的代码copy现在交过了
头像
墨染空
编辑于 2022-01-17 09:06
+ 关注

为什么把比赛wa的代码copy现在交过了

J 题
rt

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}

const int N = 50005;

int a, b, c, c0, c1, n;

string s;

signed main() {
cin >> s >> a >> b >> c;
n = s.size();
for (char c: s)
if (c == '0') c0++;
else c1++;
int ans = 1e18;
for (int i = 0; i <= n; i++) {
int t = abs(i - c0);
int j = n - i;
if (abs(i - j) % 2) continue;
int w = t * c;
w += abs(i - j) / 2 * b;
int o = min(i, j);
if (o & 1) {
w += a;
o--;
}
w += o / 2 * min(2 * b, 2 * a);
chkMin(ans, w);
}
cout << ans;
return 0;
}


全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐