提出 #61393179
ソースコード 拡げる
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; void ntom(const string str, const ll n, const ll m, string &res) { unsigned long sum = 0; for (char c : str) { sum = sum * n + (c - '0'); } res = ""; do { int num = sum % m; res = static_cast<char>(num + '0') + res; sum /= m; } while (sum); } int main() { ll L, R; cin >> L >> R; ll ans = 0; string strl = to_string(L); string strr = to_string(R); bool flag = false; for (ll i = 1; i < strl.size(); i++) { if (strl[i] - '0' >= strl[0] - '0') { flag = true; } if (flag) { strl[i] = strl[0] - 1; } } if (flag) { ans -= 1; } flag = false; for (ll i = 1; i < strr.size(); i++) { if (strr[i] - '0' >= strr[0] - '0') { flag = true; } if (flag) { strr[i] = strr[0] - 1; } } // cout << strl << " " << strr << endl; ll initial = strl[0] - '0'; ll keta = strl.size(); while ((keta < strr.size()) || (keta == strr.size() && initial <= strr[0] - '0')) { ll tmp = 1; for (ll i = 1; i < keta; i++) { tmp *= initial; } ans += tmp; // cout << "initial:" << initial << " keta:" << keta << " ans:" << ans << endl; // cout << endl; initial++; if (initial == 10) { initial = 1; keta++; } } // string tmpstr = ""; // ntom(strr.substr(1), initial, 10, tmpstr); // ans += stoll(tmpstr) + 1; initial = strl[0] - '0'; string tmpstr = ""; ntom(strl.substr(1), initial, 10, tmpstr); ans -= stoll(tmpstr); // cout << ans << endl; ll tmp = 1; for (ll i = 0; i < strr.size() - 1; i++) { tmp *= strr[0] - '0'; } initial = strr[0] - '0'; ntom(strr.substr(1), initial, 10, tmpstr); // cout << tmp << endl; // cout << stoll(tmpstr) << endl; ans -= (tmp - stoll(tmpstr)); ans += 1; cout << ans << endl; }
提出情報
提出日時 | |
---|---|
問題 | C - Snake Numbers |
ユーザ | syo__ |
言語 | C++ 23 (gcc 12.2) |
得点 | 350 |
コード長 | 2306 Byte |
結果 | AC |
実行時間 | 1 ms |
メモリ | 3792 KiB |
コンパイルエラー
Main.cpp: In function ‘int main()’: Main.cpp:32:22: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 32 | for (ll i = 1; i < strl.size(); i++) | ~~^~~~~~~~~~~~~ Main.cpp:49:22: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 49 | for (ll i = 1; i < strr.size(); i++) | ~~^~~~~~~~~~~~~ Main.cpp:64:18: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 64 | while ((keta < strr.size()) || (keta == strr.size() && initial <= strr[0] - '0')) | ~~~~~^~~~~~~~~~~~~ Main.cpp:64:42: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 64 | while ((keta < strr.size()) || (keta == strr.size() && initial <= strr[0] - '0')) | ~~~~~^~~~~~~~~~~~~~ Main.cpp:91:22: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare] 91 | for (ll i = 0; i < strr.size() - 1; i++) | ~~^~~~~~~~~~~~~~~~~
ジャッジ結果
セット名 | Sample | All | ||||
---|---|---|---|---|---|---|
得点 / 配点 | 0 / 0 | 350 / 350 | ||||
結果 |
|
|
セット名 | テストケース |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt |
ケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3656 KiB |
00_sample_01.txt | AC | 1 ms | 3656 KiB |
00_sample_02.txt | AC | 1 ms | 3600 KiB |
01_random_00.txt | AC | 1 ms | 3600 KiB |
01_random_01.txt | AC | 1 ms | 3588 KiB |
01_random_02.txt | AC | 1 ms | 3648 KiB |
01_random_03.txt | AC | 1 ms | 3592 KiB |
01_random_04.txt | AC | 1 ms | 3492 KiB |
01_random_05.txt | AC | 1 ms | 3520 KiB |
01_random_06.txt | AC | 1 ms | 3720 KiB |
01_random_07.txt | AC | 1 ms | 3600 KiB |
01_random_08.txt | AC | 1 ms | 3656 KiB |
01_random_09.txt | AC | 1 ms | 3788 KiB |
02_random2_00.txt | AC | 1 ms | 3656 KiB |
02_random2_01.txt | AC | 1 ms | 3676 KiB |
02_random2_02.txt | AC | 1 ms | 3492 KiB |
02_random2_03.txt | AC | 1 ms | 3588 KiB |
03_random3_00.txt | AC | 1 ms | 3524 KiB |
03_random3_01.txt | AC | 1 ms | 3652 KiB |
03_random3_02.txt | AC | 1 ms | 3588 KiB |
03_random3_03.txt | AC | 1 ms | 3600 KiB |
03_random3_04.txt | AC | 1 ms | 3720 KiB |
04_handmade_00.txt | AC | 1 ms | 3716 KiB |
04_handmade_01.txt | AC | 1 ms | 3600 KiB |
04_handmade_02.txt | AC | 1 ms | 3604 KiB |
04_handmade_03.txt | AC | 1 ms | 3792 KiB |
04_handmade_04.txt | AC | 1 ms | 3600 KiB |
04_handmade_05.txt | AC | 1 ms | 3588 KiB |
04_handmade_06.txt | AC | 1 ms | 3600 KiB |