1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n, x, res; map<int, int>mp; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x; mp[x]++; } int last = -1; for (auto t : mp) { if (t.second == 0) continue; res += t.first - last - 1; mp[t.first]--; if (mp[t.first] % 2 == 1) mp[t.first]++, res++; mp[t.first + 1] += mp[t.first] / 2; mp[t.first] = 0; last = t.first; } cout << res; return 0; }
- 1
信息
- ID
- 18181
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 149
- 已通过
- 46
- 上传者