美团第二题有无大佬可以帮我看看哪里有问题

一直爆0,也不知道哪里有问题
可以求求大佬们帮我分析一下吗
就美团笔试mex那道题
#美团笔试#
全部评论
```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", &amp;n, &amp;k, &amp;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; } ```
2 回复 分享
发布于 08-10 12:03 北京
首先用long long
1 回复 分享
发布于 08-10 12:00 湖北
天翼云科技有限公司
校招火热招聘中
官网直投
long 直接100%了,打过ACM或者蓝桥杯的话就会注意这些范围
1 回复 分享
发布于 08-10 12:07 浙江
我设的自测输入 1 1 3 3 1 输出0到6全都不对,是我题目理解错了嘛
1 回复 分享
发布于 08-10 12:36 重庆
define int ll
1 回复 分享
发布于 08-10 12:36 江西
中间运算j*x+right*k溢出了,直接将x和k定义成long lnog
1 回复 分享
发布于 08-12 19:22 北京

相关推荐

2 1 评论
分享
牛客网
牛客企业服务