結果

問題 No.491 10^9+1と回文
ユーザー koba-e964koba-e964
提出日時 2017-03-10 23:38:18
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 09:00:20
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 95 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

ll odd_palin(int v) {
  ll w = v;
  ll sum = 0;
  ll cur = 1;
  while (w >= 10) {
    sum *= 10;
    sum += w % 10;
    cur *= 10;
    w /= 10;
  }
  return sum + cur * v;
}
ll even_palin(int v) {
  ll w = v;
  ll sum = 0;
  ll cur = 1;
  while (w > 0) {
    sum *= 10;
    sum += w % 10;
    cur *= 10;
    w /= 10;
  }
  return sum + cur * v;
}

ll calc_palin(ll n) {
  int cnt = 0;
  REP(i, 1, 100000) {
    if (odd_palin(i) <= n) { cnt += 1; }
    if (even_palin(i) <= n) { cnt += 1; }
  }
  return cnt;
}

int main(void){
  ll n;
  cin >> n;
  cout << calc_palin(n / 1000000001) << endl;
}
0