結果

問題 No.528 10^9と10^9+7と回文
ユーザー e869120e869120
提出日時 2017-06-09 22:39:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 951 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 81,500 KB
実行使用メモリ 4,540 KB
最終ジャッジ日時 2023-10-01 00:53:04
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 9 ms
4,376 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 12 ms
4,424 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 12 ms
4,384 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 11 ms
4,540 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 9 ms
4,432 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 9 ms
4,444 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 9 ms
4,456 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 12 ms
4,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
using namespace std;
string S; long long power[100009];
long long solve(long long mod) {
	power[1] = 9; for (int i = 2; i < 100009; i++)power[i] = (power[i - 1] * 10) % mod;
	long long ret = 0;
	for (int i = 1; i < S.size(); i++)ret += power[(i + 1) / 2];
	string T = S.substr(0, ((int)S.size() + 1) / 2);
	string U = T;
	reverse(T.begin(), T.end()); if (S.size() % 2 == 1)T = T.substr(1, T.size() - 1);
	U += T;
	T = S.substr(0, ((int)S.size() + 1) / 2); ret %= mod;
	power[0] = 1; for (int i = 1; i < 100009; i++)power[i] = (power[i - 1] * 10) % mod;
	for (int i = 0; i < T.size(); i++) {
		long long B = (T[i] - '0'); if (i == 0)B--;
		ret += power[T.size() - 1 - i] * B; ret %= mod;
	}
	if (S >= U)ret++;
	return ret;
}
int main() {
	cin >> S;
	cout << solve(1000000000) << endl << solve(1000000007) << endl;
	return 0;
}
0