美团第二题有无大佬可以帮我看看哪里有问题
全部评论
```c++
#include <iostream>
(30316)#include <vector>
#include <cstring>
(31637)#include <algorithm>
using namespace std;
typedef unsigned long long LL;
const int N = 200010;
LL a[N];
LL mex[N];
LL cnt[N];
int main() {
int T;
cin >> T;
while (T--) {
memset(a, 0, sizeof a);
memset(mex, 0, sizeof mex);
memset(cnt, 0, sizeof cnt);
LL n, k, x;
scanf("%lld%lld%lld", &n, &k, &x);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
cnt[a[i]]++;
}
LL mx = 0;
while (cnt[mx]) mx++;
mex[0] = mx;
for (int i = 1; i < n; i++) {
cnt[a[i - 1]]--;
if (cnt[a[i - 1]] == 0) mx = min(mx, a[i - 1]);
mex[i] = mx;
}
LL res = 0x3f3f3f3f;
res = res * res;
LL sum = 0;
for (int i = 0; i < n; i++) {
res = min(res, sum + k * mex[i]);
sum += x;
}
res = min(res, sum);
cout << res << endl;
}
return 0;
}
```
首先用long long
long 直接100%了,打过ACM或者蓝桥杯的话就会注意这些范围
我设的自测输入
1
1 3 3
1
输出0到6全都不对,是我题目理解错了嘛
define int ll
中间运算j*x+right*k溢出了,直接将x和k定义成long lnog
相关推荐
09-14 16:58
门头沟学院 Java 点赞 评论 收藏
分享