結果

問題 No.1849 Three Times Value
ユーザー tnakao0123tnakao0123
提出日時 2022-02-25 14:36:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 41,792 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 06:58:35
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:45:33: 警告: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
   45 |   if (x * (t * t + t + 1) > n) x--;
      |                                ~^~
main.cpp:37:6: 備考: ‘x’ はここで定義されています
   37 |   ll x;
      |      ^

ソースコード

diff #

/* -*- 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;
}
0