結果
| 問題 | No.491 10^9+1と回文 | 
| コンテスト | |
| ユーザー |  tottoripaper | 
| 提出日時 | 2017-03-10 23:43:23 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 1,000 ms | 
| コード長 | 1,418 bytes | 
| コンパイル時間 | 1,230 ms | 
| コンパイル使用メモリ | 159,492 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-01 08:21:02 | 
| 合計ジャッジ時間 | 3,839 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 103 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
template <typename T>
T expt(T a, T n){
    T res = 1;
    while(n){
        if(n & 1){res = res * a;}
        a = a * a;
        n >>= 1;
    }
    return res;
}
int s[100];
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll N;
    std::cin >> N;
    ll res = 0ll;
    
    for(int i=1;i<=9;++i){
        // printf("Phase %d:\n", i);
        int mx = expt(10,(i+1)/2);
        for(int j=1;j<mx;++j){
            if(j % 10 == 0){continue;}
            
            int x = j, idx = 0;
            memset(s, 0, sizeof(s));
            
            while(x > 0){
                s[idx] = x % 10;
                x /= 10;
                ++idx;
            }
            for(int k=0;k<(i+1)/2;k++){
                s[i-1-k] = s[k];
            }
            ll y = 0ll;
            for(int k=8;k>=0;--k){
                y = y * 10 + s[k];
            }
            y *= 1000000000 + 1;
            if(y <= N){++res;}
            // if(y <= N){
            //     printf("%d, %lld\n", j, y);
            //     printf("%c\n", "xo"[y<=N]);
            // }
        }
    }
    printf("%lld\n", res);
}
            
            
            
        