forked from Yawn-Sean/Daily_CF_Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240430 Create cf1267j_ToC.cpp (Yawn-Sean#1842)
- Loading branch information
1 parent
80d160f
commit 724cfc5
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
daily_problems/2024/04/0429/personal_submission/cf1267j_ToC.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// https://codeforces.com/contest/1267/submission/258854772 | ||
void sol() | ||
{ | ||
cin >> n; | ||
int x; | ||
unordered_map<int, int> v2c; | ||
for (int i = 1; i <= n; i++) { | ||
cin >> x; | ||
v2c[x]++; | ||
} | ||
vector<int> cnt; | ||
for (auto &[v, c] : v2c) { | ||
cnt.push_back(c); | ||
} | ||
int sup = *min_element(cnt.begin(), cnt.end()) + 1; | ||
int inf = 2, res = INF; | ||
for (int s = sup; s >= inf; s--) { | ||
bool flag = true; | ||
int tmp = 0; | ||
for (auto &c : cnt) { | ||
/* | ||
先有q个完整的s,最后一个是不完整的r | ||
如果r == 0或者r == s -1,就不用补最后一个 | ||
如果 1 <= r <= s - 2,那么需要补充s - 1 - r到最后一个 | ||
需要从前面的q个填满的里面,每个取一个放到最后,所以需要q >= s - 1 - r | ||
*/ | ||
int q = c / s, r = c % s; | ||
if ((r == 0) || (r == s - 1) || (q >= s - 1 - r)) { | ||
tmp += (c + s - 1) / s; | ||
} else { | ||
flag = false; break; | ||
} | ||
} | ||
if (flag) { | ||
res = min(res, tmp); | ||
} | ||
} | ||
cout << res << '\n'; | ||
} |