結果
| 問題 |
No.2221 Set X
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-05 10:07:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 181 ms / 2,000 ms |
| コード長 | 1,028 bytes |
| コンパイル時間 | 310 ms |
| コンパイル使用メモリ | 40,812 KB |
| 最終ジャッジ日時 | 2025-02-22 02:11:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:49:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- 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 + 1];
/* subroutines */
ll f(int n, int x, ll minf) {
int c = 1;
for (int i = 0; i < n;) {
int ai = as[i] / x;
int j0 = i, j1 = n + 1;
while (j0 + 1 < j1) {
int j = (j0 + j1) / 2;
if (as[j] / x > ai) j1 = j;
else j0 = j;
}
i = j1;
if (i < n) {
c++;
if ((ll)(x + 1) * c >= minf) return minf;
}
}
return (ll)(x + 1) * c;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
as[n] = as[n - 1] * 2 + 2;
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;
}
tnakao0123