結果

問題 No.491 10^9+1と回文
ユーザー tottoripapertottoripaper
提出日時 2017-03-10 23:26:49
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,587 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 158,612 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 08:46:36
合計ジャッジ時間 4,307 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 WA * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        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){
        int mx = expt(10,(i+1)/2);
        for(int j=1;j<mx;++j){
            if(j % 10 == 0){continue;}
            
            int x = j, idx = 0;
            
            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];
            }

            for(int k=0;k<i;++k){
                s[k+9] = s[k];
            }

            auto f = [](){
                for(int i=17;i>=0;--i){
                    printf("%d", s[i]);
                }
                puts("");
            };


            ll y = 0ll;
            for(int k=17;k>=0;--k){
                y = y * 10 + s[k];
            }

            if(y <= N){++res;}
            // if(y <= N){
            //     f();
            //     printf("%c\n", "xo"[y<=N]);
            // }
        }
    }

    printf("%lld\n", res);
}
0