結果
| 問題 | No.491 10^9+1と回文 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-10 23:05:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 1,000 ms |
| コード長 | 1,108 bytes |
| 記録 | |
| コンパイル時間 | 1,152 ms |
| コンパイル使用メモリ | 102,580 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 07:10:24 |
| 合計ジャッジ時間 | 7,643 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 103 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
int ten(int x)
{
if (x == 0)return 1;
return ten(x - 1) * 10;
}
int main(void)
{
ll n;
cin >> n;
int ans = 0;
for (int d = 1; d <= 9; ++d)
{
int half = d / 2 + (d % 2);
int dow = ten(half - 1);
int lim = ten(half);
for (int i = dow; i < lim; ++i)
{
//if (i % 10 == 0)continue;
char form[20];
sprintf(form, "%%0%dd", half);
char str[20];
char rev[20];
sprintf(str, form, i);
strcpy(rev, str);
reverse(rev, rev + half);
if (d % 2)str[d / 2] = '\0';
strcat(str, rev);
ll out = atoll(str);
out *= 1000000001;
if (out <= n)
{
cerr << out << endl;
ans++;
}
}
}
cout << ans << endl;
return 0;
}