結果

問題 No.3269 Leq-K Partition
ユーザー tnakao0123
提出日時 2025-09-16 18:45:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 854 ms / 6,000 ms
コード長 1,259 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 61,280 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-16 18:45:36
合計ジャッジ時間 17,214 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:48:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |   for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3269.cc:  No.3269 Leq-K Partition - yukicoder
 */

#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];
bool used[MAX_N];
int res[MAX_N + 1];

/* subroutines */

int calc(int n, int k) {
  int cnt = 0;
  for (int i = 0; i < n;) {
    int j = i, s = 0;
    while (i < n && (s < k || (s == k && used[as[i]]))) {
      if (! used[as[i]]) s++, used[as[i]] = true;
      i++;
    }

    cnt++;

    for (; j < i; j++) used[as[j]] = false;
  }

  return cnt;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;

  if (n <= 100) {
    for (int k = 1; k <= n; k++) res[k] = calc(n, k);
  }
  else {
    int b = sqrt(log2(n) * n);
    //printf(" b=%d\n", b);

    for (int k = 1; k <= b; k++) res[k] = calc(n, k);

    int maxq = (n + b - 1) / b;
    for (int q = 1, pk = n; q <= maxq; q++) {
      int k0 = 0, k1 = n;
      while (k0 + 1 < k1) {
	int k = (k0 + k1) / 2;
	if (calc(n, k) <= q) k1 = k;
	else k0 = k;
      }
      
      while (pk >= k1) res[pk--] = q;
    }
  }
  
  for (int k = 1; k <= n; k++) printf("%d\n", res[k]);
  
  return 0;
}
0