結果
問題 |
No.491 10^9+1と回文
|
ユーザー |
![]() |
提出日時 | 2017-03-11 02:30:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,517 bytes |
コンパイル時間 | 987 ms |
コンパイル使用メモリ | 76,860 KB |
実行使用メモリ | 59,648 KB |
最終ジャッジ日時 | 2024-06-24 09:34:57 |
合計ジャッジ時間 | 14,603 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 WA * 56 RE * 1 |
ソースコード
#include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; typedef long long ll; ll a[15]; int digit(ll a); vector<string>v[15]; int main() { ll N; scanf("%lld",&N); int i, j, k; a[1] = 9ll; a[2] = 9ll; for (i = 3; i < 12; i+=2) { a[i] = (a[i - 1] + 1ll) * 9ll; a[i + 1] = a[i]; } if (N < 1000000001ll) { printf("0\n"); } else { ll sum = 0ll; int d = digit(N); for (i = 10; i < d; i++) { sum += a[i - 9]; } for (i = 1; i <= 9; i++) { string s = to_string(i); for (j = 1; j <= 8; j++) { s += to_string(0); } s += to_string(i); v[1].push_back(s); } for (i = 11; i <= 99; i++) { if (i / 10 == i % 10) { string s = to_string(i); for (j = 1; j <= 7; j++) { s += to_string(0); } s += to_string(i); v[2].push_back(s); } } for (i = 3; i <= 11; i++) { for (k = 1; k <= 9; k++) { string ss = to_string(k); for (j = 0; j < i - 2; j++) { ss += to_string(0); } ss += to_string(k); v[i].push_back(ss); } for (k = 1; 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); } } } for (i = 0; i < v[d - 9].size(); i++) { if (stoll(v[d - 9][i])<=N) { sum += 1ll; } } printf("%lld\n",sum); } return 0; } int digit(ll a) { int ret = 0; while (1) { if (a == 0ll) { break; } ret++; a /= 10ll; } return ret; }