用std::map<int,long long>维护当前种子的个数,暴力模拟即可。
虽然单词模拟复杂度是,但是因为种子的种类数每次是除 3,所以总的复杂度实际上不超过
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n;
cin >> n;
map<int, i64> cnt;
for (int i = 0, x; i < n; i++) {
cin >> x;
cnt[x]++;
}
int p;
cin >> p;
i64 res = cnt[p];
while (cnt.rbegin()->first >= p) {
res = max(res, cnt[p]);
map<int, i64> new_cnt;
for (auto [x, v]: cnt) {
int y = (x + 2) / 3;
new_cnt[y] += v * 2;
}
cnt = move(new_cnt);
}
cout << res;
return 0;
}

京公网安备 11010502036488号