結果
問題 |
No.491 10^9+1と回文
|
ユーザー |
![]() |
提出日時 | 2017-03-10 22:56:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,404 bytes |
コンパイル時間 | 1,635 ms |
コンパイル使用メモリ | 169,760 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 08:30:10 |
合計ジャッジ時間 | 6,093 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 77 TLE * 1 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) typedef long long ll; ll N; //----------------------------------------------------------------- int main() { cin >> N; ll mo = 1000000001; int dig = 0; ll t = N; while (0 < t) dig++, t /= 10; ll ans = 0; rrep(i, 8, 1) { ll c = 0; int d = i + 2 * (9 - i); if (d < dig) { // 全部OK int j = 9 - i; if (j == 1) { c = 9; } else if(j % 2 == 0){ int k = j / 2 - 1; c = 9; rep(kk, 0, k) c *= 10; ans += c; } else { int k = j / 2; c = 9; rep(kk, 0, k) c *= 10; ans += c; } } else if (d == dig) { // 一部OK int j = 9 - i; string n = to_string(N); int ma = 0; rep(i, 0, j) ma = ma * 10 + n[i] - '0'; int mi = 0; rep(i, 0, j) mi = mi * 10 + 1; rep(x, mi, ma) { string s = to_string(x); bool ok = true; rep(i, 0, s.length() / 2 + 1) { int j = s.length() - 1 - i; if (s[i] != s[j]) ok = false; } if (ok) c++; } ll th = ma; rep(i, 0, d - j * 2) th *= 10; int y = ma; while (0 < y) { th = th * 10 + y % 10; y /= 10; } if (th <= N) c++; //cout << th << endl; /*cout << j << endl; cout << ma << endl; cout << mi << endl;*/ } ans += c; //printf("%d -> %lld\n", d, c); } cout << ans << endl; }