結果

問題 No.491 10^9+1と回文
ユーザー face4
提出日時 2019-02-03 16:35:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 1,000 ms
コード長 645 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 70,836 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 18:11:11
合計ジャッジ時間 4,720 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 103
権限があれば一括ダウンロードができます

ソースコード

diff #

// プロの解説ブログを見た
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;

    n /= (ll)1e9+1;

    int ans = 0;
    for(ll i = 1; i < 100000; i++){
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());
        
        // 偶数長の回文
        ll tmp = stoll(s+t);
        if(tmp <= n)    ans++;
        
        // 奇数長の回文
        if(s.back() == t.front()){
            s.pop_back();
            tmp = stoll(s+t);
            if(tmp <= n)    ans++;
        }
    }

    cout << ans << endl;

    return 0;
}
0