結果
問題 |
No.3269 Leq-K Partition
|
ユーザー |
![]() |
提出日時 | 2025-09-13 00:49:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,082 ms / 6,000 ms |
コード長 | 1,674 bytes |
コンパイル時間 | 3,511 ms |
コンパイル使用メモリ | 286,680 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-13 00:49:42 |
合計ジャッジ時間 | 33,019 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; int N; vector<int> A; vector<bool> F; int func(int k) { int ans = 0; int cnt = 0; vector<int> history; for (int a : A) { if (!F[a-1]) { if (cnt == k) { ans++; while (!history.empty()) { F[history.back()] = false; history.pop_back(); } cnt = 0; } cnt++; F[a-1] = true; history.push_back(a-1); } } while (!history.empty()) { F[history.back()] = false; history.pop_back(); } return ans + 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; A.resize(N); for (int i = 0; i < N; i++) cin >> A[i]; if (N == 1) { cout << 1 << "\n"; return 0; } F.assign(N, false); int route = (int)(pow(N, 0.6)) + 1; vector<int> ans; for (int k = 1; k <= route; k++) { ans.push_back(func(k)); } int left = route; while (left <= N) { int now = ans.back(); int idx = (int)ans.size(); int right = N + 1; while (left + 1 < right) { int mid = (left + right) / 2; if (func(mid) == now) { left = mid; } else { right = mid; } } for (int i = 0; i < right - idx - 1; i++) { ans.push_back(now); } if (right <= N) { ans.push_back(func(right)); } left = right; } for (int a : ans) { cout << a << "\n"; } return 0; }