結果

問題 No.2246 1333-like Number
ユーザー lotokalotoka
提出日時 2023-04-16 21:48:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 70,608 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 03:49:34
合計ジャッジ時間 1,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 3 ms
6,820 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 2 ms
6,816 KB
testcase_08 AC 2 ms
6,816 KB
testcase_09 AC 2 ms
6,816 KB
testcase_10 AC 2 ms
6,820 KB
testcase_11 AC 3 ms
6,820 KB
testcase_12 AC 2 ms
6,820 KB
testcase_13 AC 2 ms
6,820 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 AC 2 ms
6,816 KB
testcase_16 AC 2 ms
6,820 KB
testcase_17 AC 2 ms
6,816 KB
testcase_18 AC 2 ms
6,816 KB
testcase_19 AC 2 ms
6,820 KB
testcase_20 AC 2 ms
6,820 KB
testcase_21 AC 2 ms
6,816 KB
testcase_22 AC 2 ms
6,816 KB
testcase_23 AC 2 ms
6,820 KB
testcase_24 AC 2 ms
6,816 KB
testcase_25 AC 2 ms
6,820 KB
testcase_26 AC 2 ms
6,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/basic_string.h:3969,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
In function 'void std::__detail::__to_chars_10_impl(char*, unsigned int, _Tp) [with _Tp = unsigned int]',
    inlined from 'std::string std::__cxx11::to_string(int)' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/basic_string.h:4029:33,
    inlined from 'int main()' at main.cpp:25:25:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/charconv.h:92:7: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   92 |       if (__val >= 10)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:5:12: note: 'b' was declared here
    5 |     int a, b, c;
      |            ^
main.cpp:23:29: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   23 |     string ans = to_string(a);
      |                             ^
main.cpp:5:9: note: 'a' was declared here
    5 |     int a, b, c;
      |         ^

ソースコード

diff #

#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    int N;
    cin >> N;

    c = (N - 1) / 36 + 1;    //cは単純な計算で算出
    int temp = (N - 1) % 36 + 1;    //abの値を出すため

    int sum = 0;    //今後の判別用

    for (int i = 1; i < 9; ++i) {    //大量のif文を繋げる事もできるがスマートでないためfor文を用いる. a, bの値を定める.
        if (sum + 1 <= temp && temp <= sum + 9 - i) {
            a = i;
            b = i + temp - sum;
            break;    //a,bの値が定まればこのfor文に用はなくなるので脱出
        }
        sum += 9 - i;
    }

    string ans = to_string(a);
    for (int i = 0; i < c; ++i) {
        ans += to_string(b);
    }

    cout << ans << endl;

    return 0;
}
0