結果
| 問題 |
No.2221 Set X
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-05 09:39:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 870 bytes |
| コンパイル時間 | 391 ms |
| コンパイル使用メモリ | 40,832 KB |
| 最終ジャッジ日時 | 2025-02-22 02:10:55 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:42:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | 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];
/* 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;
}
tnakao0123