結果
問題 | No.491 10^9+1と回文 |
ユーザー |
![]() |
提出日時 | 2017-03-11 18:35:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 10 ms / 1,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 584 ms |
コンパイル使用メモリ | 57,716 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 08:31:07 |
合計ジャッジ時間 | 3,348 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 103 |
ソースコード
#include <iostream>#include <string>#define int long longusing namespace std;int high;string reverse(string s) {string ret;for (int i = (int)s.length() - 1; i >= 0; i--) ret += s[i];return ret;}bool check(string s) {//0文字目は最下位桁if (s.length() == 0 || s[s.length() - 1] == '0') return false;int value = 0;int mul = 1;for (int i = 0; i < s.length(); i++) {value += (s[i] - '0') * mul;mul *= 10;}if (1 <= value && value <= high) return true;return false;}int dfs(string s) {if (s.length() > 4) return 0;int ret = 0;if (check(s + reverse(s))) ret++;for (char i = '0'; i <= '9'; i++) {if (check(s + i + reverse(s))) ret++;}for (char i = '0'; i <= '9'; i++) {ret += dfs(s + i);}return ret;}signed main() {int n;cin >> n;high = n / 1000000001;cout << dfs("") << endl; //1以上high以下の回文がいくつあるか?return 0;}