結果

問題 No.528 10^9と10^9+7と回文
ユーザー olpheolphe
提出日時 2017-06-09 23:27:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 2,257 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 111,084 KB
実行使用メモリ 8,328 KB
最終ジャッジ日時 2023-10-01 00:53:35
合計ジャッジ時間 2,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,016 KB
testcase_01 AC 5 ms
8,044 KB
testcase_02 AC 5 ms
8,040 KB
testcase_03 AC 5 ms
8,108 KB
testcase_04 AC 6 ms
8,328 KB
testcase_05 AC 5 ms
8,008 KB
testcase_06 AC 5 ms
8,108 KB
testcase_07 AC 5 ms
8,216 KB
testcase_08 AC 5 ms
8,104 KB
testcase_09 AC 5 ms
8,036 KB
testcase_10 AC 5 ms
8,240 KB
testcase_11 AC 6 ms
8,136 KB
testcase_12 AC 5 ms
8,176 KB
testcase_13 AC 5 ms
8,144 KB
testcase_14 AC 5 ms
8,236 KB
testcase_15 AC 5 ms
8,216 KB
testcase_16 AC 5 ms
8,164 KB
testcase_17 AC 5 ms
8,104 KB
testcase_18 AC 5 ms
8,276 KB
testcase_19 AC 5 ms
8,060 KB
testcase_20 AC 5 ms
8,172 KB
testcase_21 AC 5 ms
8,100 KB
testcase_22 AC 5 ms
8,012 KB
testcase_23 AC 5 ms
8,004 KB
testcase_24 AC 5 ms
8,020 KB
testcase_25 AC 5 ms
8,140 KB
testcase_26 AC 5 ms
8,172 KB
testcase_27 AC 6 ms
8,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, K, Q;

string s;
long long int num[100001];
long long int box[100001];
long long int s_num[100001];
long long int s_box[100001];
long long int t_num[100001];
long long int t_box[100001];

int main() {
	ios::sync_with_stdio(false);
	cin >> s;
	num[1] = 9;
	num[2] = 9;
	box[1] = 9;
	box[2] = 9;
	t_num[0] = 1;
	t_box[0] = 1;
	for (int i = 3; i <= 100000; i++) {
		num[i] = num[i - 2] * 10;
		num[i] %= MOD;
		box[i] = box[i - 2] * 10;
		box[i] %= 1000000000;
	}
	for (int i = 1; i <= 100000; i++) {
		s_num[i] = s_num[i - 1] + num[i];
		s_num[i] %= MOD;
		s_box[i] = s_box[i - 1] + box[i];
		s_box[i] %= 1000000000;
		t_num[i] = t_num[i - 1] * 10;
		t_num[i] %= MOD;
		t_box[i] = t_box[i - 1] * 10;
		t_box[i] %= 1000000000;
	}
	long long int ans_box = s_box[s.size() - 1];
	long long int ans_num = s_num[s.size() - 1];
	ans_box += (s[0] - '1')*t_box[(s.size()-1) / 2];
	ans_num += (s[0] - '1')*t_num[(s.size()-1) / 2];
	bool flag = true;
	for (int i = s.size()/2-1; i >= 0; i--) {
		if (s[i] > s[s.size() - i - 1]) {
			flag = false;
			break;
		}
		if (s[i] < s[s.size() - i - 1]) {
			break;
		}
	}
	//cout << ans_box << endl << ans_num << endl;
	for (int i = 1; i < (s.size() + 1) / 2; i++) {
		ans_box += (s[i] - '0')*t_box[(s.size() - 1) / 2 - i];
		ans_num += (s[i] - '0')*t_num[(s.size() - 1) / 2 - i];
	}
	//cout << ans_box << endl << ans_num << endl;
	if (flag) {
		ans_box++;
		ans_num++;
	}
	ans_box %= 1000000000;
	ans_num %= MOD;
	cout << ans_box << endl << ans_num << endl;
	return 0;
}
0