結果

問題 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
コンパイル時間 742 ms
コンパイル使用メモリ 72,448 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 08:27:07
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
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;
      |         ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/string:54,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ios:44,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ostream:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/iostream:41,
                 from main.cpp:1:
In function 'std::string std::__cxx11::to_string(int)',
    inlined from 'int main()' at main.cpp:25:25:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/basic_string.h:4156:35: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
 4156 |     const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
      |                             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function 'int main()':
main.cpp:5:12: note: 'b' 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