結果
問題 | No.491 10^9+1と回文 |
ユーザー | tekitouk |
提出日時 | 2017-03-11 07:00:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 1,000 ms |
コード長 | 1,260 bytes |
コンパイル時間 | 744 ms |
コンパイル使用メモリ | 76,680 KB |
実行使用メモリ | 43,424 KB |
最終ジャッジ日時 | 2024-10-01 08:29:13 |
合計ジャッジ時間 | 11,459 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 103 |
ソースコード
#include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; typedef long long ll; int b[10] = { 9,8,7,6,5,4,3,2,1,0 }; int digit(ll a); vector<string>v[15]; int main() { ll N; scanf("%lld",&N); int i, j, k; if (N < 1000000001ll) { printf("0\n"); } else { int d = digit(N); if (d == 19) { d = 18; N = 999999999999999999ll; } for (i = 0; i <= 9; i++) { v[1].push_back(to_string(i)); } v[2].push_back("00"); for (i = 11; i <= 99; i++) { if (i / 10 == i % 10) { v[2].push_back(to_string(i)); } } for (i = 3; i <= 11; i++) { for (k = 0; k <= 9; k++) { for (j = 0; j < v[i - 2].size(); j++) { string s = to_string(k); s += v[i - 2][j]; s += to_string(k); v[i].push_back(s); } } } ll ans = 0ll; for (k = 1; k <= d - 9; k++) { for (i = 0; i < v[k].size(); i++) { string s = v[k][i]; for (j = 0; j < b[k]; j++) { s += to_string(0); } s += v[k][i]; if (s[0] == '0') { continue; } if (stoll(s) <= N) { ans += 1ll; } } } printf("%lld\n", ans); } return 0; } int digit(ll a) { int ret = 0; while (1) { if (a == 0ll) { break; } ret++; a /= 10ll; } return ret; }