結果
| 問題 |
No.1849 Three Times Value
|
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-02-25 14:36:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 703 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 42,052 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-03 08:31:27 |
| 合計ジャッジ時間 | 1,470 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:33: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized]
45 | if (x * (t * t + t + 1) > n) x--;
| ~^~
main.cpp:37:6: note: 'x' was declared here
37 | ll x;
| ^
ソースコード
/* -*- coding: utf-8 -*-
*
* 1849.cc: No.1849 Three Times Value - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
/* typedef */
typedef long long ll;
/* global variables */
/* subroutines */
/* main */
int main() {
ll n;
scanf("%lld", &n);
int k = 0;
for (ll m = n; m > 0; m /= 10) k++;
//printf("k=%d\n", k);
int l = k / 3, r = k % 3;
if (l == 0) { puts("0"); return 0; }
ll t = 1;
for (int i = 0; i < l; i++) t *= 10;
ll x;
if (r == 0) {
x = n;
for (int i = k; i > l; i--) x /= 10;
}
else
for (int i = 0; i < l; i++) x = x * 10 + 9;
if (x * (t * t + t + 1) > n) x--;
printf("%lld\n", x);
return 0;
}
tnakao0123