結果

問題 No.491 10^9+1と回文
ユーザー kk
提出日時 2020-09-02 02:34:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 1,000 ms
コード長 843 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 199,244 KB
最終ジャッジ日時 2025-01-14 03:31:00
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 103
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

vector<int> num[5];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  for (int i = 1; i <= 1e5; i++) {
    string s = to_string(i);
    num[s.length()].push_back(i);
  }

  vector<int> cand { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  
  for (int d = 2; d <= 9; d++) {
    int h = d / 2;
    for (int x: num[h]) {
      string s = to_string(x);
      string t = s;
      reverse(t.begin(), t.end());

      if (d % 2) {
        for (char c = '0'; c <= '9'; c++) 
          cand.emplace_back(stoi(s + c + t));
      } else {
        cand.emplace_back(stoi(s + t));
      }
    }
  }

  long long n;
  cin >> n;

  long long ret = 0;
  for (long long x: cand) {
    if (x * 1000000001 <= n)
      ++ret;
  }
  cout << ret << endl;
  
  return 0;
}
0