結果

問題 No.2221 Set X
ユーザー tnakao0123tnakao0123
提出日時 2024-07-05 09:39:46
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 870 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 44,084 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-07-05 09:39:51
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 1 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2221.cc:  No.2221 Set X - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

using ll = long long;

/* global variables */

int as[MAX_N];

/* subroutines */

ll f(int n, int x, ll minf) {
  int c = 0, pa = -1;
  for (int i = 0; i < n; i++) {
    int ax = as[i] / x;
    if (pa != ax) {
      c++, pa = ax;
      if ((ll)(x + 1) * c > minf) return minf + 1;
    }
  }
  return (ll)(x + 1) * c;
}

/* main */

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

  int maxx = n * 2, minx = 1;
  ll minf = n * 2;
  for (int x = 1; x <= maxx; x++) {
    ll fx = f(n, x, minf);
    if (minf > fx) minf = fx, minx = x;
    //printf(" %lld", fx);
  }
  //putchar('\n');

  printf("%d\n%lld\n", minx, minf);

  return 0;
}
0