結果
問題 |
No.3269 Leq-K Partition
|
ユーザー |
|
提出日時 | 2025-09-13 15:45:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,150 bytes |
コンパイル時間 | 1,937 ms |
コンパイル使用メモリ | 202,976 KB |
実行使用メモリ | 139,540 KB |
最終ジャッジ日時 | 2025-09-13 15:45:45 |
合計ジャッジ時間 | 10,552 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | for (int i = 1; i < n + 1; i++) scanf("%d", w + i); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int N = 2000086, MOD = 1e9 + 7, INF = 0x3f3f3f3f; ll res; int n, m, cnt, w[N]; struct Node { int l, r; map<int, int> ma; }e[N]; int main() { cin >> n; for (int i = 1; i < n + 1; i++) scanf("%d", w + i); int sz = n; for (int i = 1; i < n + 1; i++) e[i].l = e[i].r = i, e[i].ma[w[i]]++; for (int t = 1; t < n + 1; t++) { int pre = 0; for (int i = 1; i < sz + 1; i++) { while (e[i].l <= pre) { if (e[i].ma.count(w[e[i].l])) { e[i].ma[w[e[i].l]]--; if (!e[i].ma[w[e[i].l]]) e[i].ma.erase(w[e[i].l]); } e[i].l++; } if (!e[i].ma.size()) e[i].r = e[i].l, e[i].ma[w[e[i].l]]++; while (e[i].r + 1 <= n && (e[i].ma.size() < t || e[i].ma.count(w[e[i].r + 1]))) { e[i].r++; e[i].ma[w[e[i].r]]++; } if (e[i].r == n) { sz = i; break; } pre = e[i].r; } printf("%d\n", sz); } return 0; }