結果
| 問題 | No.491 10^9+1と回文 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-10 22:39:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 1,000 ms |
| コード長 | 813 bytes |
| 記録 | |
| コンパイル時間 | 638 ms |
| コンパイル使用メモリ | 81,192 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 07:08:50 |
| 合計ジャッジ時間 | 3,783 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 103 |
ソースコード
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
vector<unsigned long long> a;
unsigned long long stoiii(string s) {
unsigned long long val = 0;
for (char c : s) {
val = val * 10 + (c - '0');
}
return val;
}
void dfs(string curr) {
if (!curr.empty() && curr[0] != '0') {
a.push_back(stoiii(curr));
}
if (curr.size() >= 9) {
return;
}
for (int i = 0; i < 10; i++) {
string c(1, i + '0');
dfs(c + curr + c);
}
}
int main() {
long long n;
cin >> n;
dfs("");
for (int i = 0; i < 10; i++) {
dfs(string(1, '0' + i));
}
int ans = 0;
for (unsigned long long x : a) {
unsigned long long y = 1000000000 * x + x;
if (y <= n) {
ans++;
}
}
cout << ans << endl;
}