結果

問題 No.491 10^9+1と回文
ユーザー naimonon77naimonon77
提出日時 2017-03-11 22:38:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 2,511 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 179,824 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 16:18:10
合計ジャッジ時間 4,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 12 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 3 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 2 ms
6,676 KB
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 2 ms
6,676 KB
testcase_56 AC 2 ms
6,676 KB
testcase_57 AC 2 ms
6,676 KB
testcase_58 AC 2 ms
6,676 KB
testcase_59 AC 2 ms
6,676 KB
testcase_60 AC 2 ms
6,676 KB
testcase_61 AC 2 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
testcase_63 AC 2 ms
6,676 KB
testcase_64 AC 2 ms
6,676 KB
testcase_65 AC 2 ms
6,676 KB
testcase_66 AC 2 ms
6,676 KB
testcase_67 AC 4 ms
6,676 KB
testcase_68 AC 2 ms
6,676 KB
testcase_69 AC 2 ms
6,676 KB
testcase_70 AC 2 ms
6,676 KB
testcase_71 AC 2 ms
6,676 KB
testcase_72 AC 2 ms
6,676 KB
testcase_73 AC 2 ms
6,676 KB
testcase_74 AC 2 ms
6,676 KB
testcase_75 AC 2 ms
6,676 KB
testcase_76 AC 2 ms
6,676 KB
testcase_77 AC 2 ms
6,676 KB
testcase_78 AC 2 ms
6,676 KB
testcase_79 AC 2 ms
6,676 KB
testcase_80 AC 2 ms
6,676 KB
testcase_81 AC 1 ms
6,676 KB
testcase_82 AC 3 ms
6,676 KB
testcase_83 AC 2 ms
6,676 KB
testcase_84 AC 2 ms
6,676 KB
testcase_85 AC 2 ms
6,676 KB
testcase_86 AC 2 ms
6,676 KB
testcase_87 AC 2 ms
6,676 KB
testcase_88 AC 1 ms
6,676 KB
testcase_89 AC 2 ms
6,676 KB
testcase_90 AC 2 ms
6,676 KB
testcase_91 AC 2 ms
6,676 KB
testcase_92 AC 2 ms
6,676 KB
testcase_93 AC 2 ms
6,676 KB
testcase_94 AC 2 ms
6,676 KB
testcase_95 AC 2 ms
6,676 KB
testcase_96 AC 2 ms
6,676 KB
testcase_97 AC 4 ms
6,676 KB
testcase_98 AC 12 ms
6,676 KB
testcase_99 AC 10 ms
6,676 KB
testcase_100 AC 10 ms
6,676 KB
testcase_101 AC 8 ms
6,676 KB
testcase_102 AC 9 ms
6,676 KB
testcase_103 AC 12 ms
6,676 KB
testcase_104 AC 12 ms
6,676 KB
testcase_105 AC 12 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}


string reverse_res(string s) {
	reverse(all(s));
	return s;
}

int n;
set<int> set1;

void solve() {
	set1.clear();
	cin >> n;
	int mod_n = (int)1e9;
	int cnt = 0;

	rep2(i, 1, mod_n) {
		string s1 = to_string(i);
		string s2 = reverse_res(s1);
		string s3 = s1 + s2;
		int a = stoll(s3);
		if (a >= mod_n) break;
		int b = a * mod_n + a;
		if (n < b) break;
		cnt++;
		if (test) dump(b);
	}

	rep(i, mod_n) {
		rep2(j, 0, 10) {
			string s1 = to_string(i);
			string s2 = reverse_res(s1);
			if (i == 0 && j == 0) continue;
			if (i == 0) s1 = s2 = "";
			string s3 = s1 + to_string(j) + s2;
			int a = stoll(s3);
			if (a >= mod_n) goto end;
			int b = a * mod_n + a;
			if (n < b) goto end;
			cnt++;
			if (test) dump(b);
		}
	}
end:
	cout << cnt << endl;
}

signed main() {
	srand(time(NULL));
	int T = 100;
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}
0