結果
| 問題 |
No.491 10^9+1と回文
|
| コンテスト | |
| ユーザー |
le_panda_noir
|
| 提出日時 | 2020-06-14 12:47:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 1,000 ms |
| コード長 | 956 bytes |
| コンパイル時間 | 1,494 ms |
| コンパイル使用メモリ | 106,384 KB |
| 最終ジャッジ日時 | 2025-01-11 04:15:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 103 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
template<class T>using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
int main() {
ll N; cin >> N;
if (N < 1000000001) {
cout << "0\n";
return 0;
}
int ans = 0;
int n = N / 1000000001LL;
// n以下の数字のうち回文である個数を求めれば良い
priority_queue_rev<pair<int, pair<ll, string>>> q;
rep(i, 10)
q.emplace(1, make_pair(i, to_string(i)));
q.emplace(1, make_pair(0, ""));
while (!q.empty()) {
auto [idx, e] = q.top(); q.pop();
auto [p, s] = e;
if (p > n) break;
if (s[0] != '0' && p != 0) {
++ans;
}
if (idx > 4)
continue;
rep(i, 10) {
string s2 = to_string(i) + s + to_string(i);
q.emplace(idx+1, make_pair(stoll(s2), s2));
}
}
cout << ans << endl;
return 0;
}
le_panda_noir