結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー | Pachicobue |
提出日時 | 2017-06-10 00:39:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,924 bytes |
コンパイル時間 | 1,722 ms |
コンパイル使用メモリ | 170,660 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 21:16:58 |
合計ジャッジ時間 | 2,550 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 6 ms
6,940 KB |
testcase_11 | AC | 6 ms
6,940 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 5 ms
6,944 KB |
testcase_21 | WA | - |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 3 ms
6,940 KB |
testcase_26 | AC | 6 ms
6,940 KB |
testcase_27 | AC | 6 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--) #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define fst first #define snd second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define pii pair<int, int> #define vi vector<int> using namespace std; template <class S, class T> ostream& operator<<(ostream& o, const pair<S, T>& p) { return o << "(" << p.first << "," << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& vc) { o << "sz = " << vc.size() << endl << "["; for (const T& v : vc) o << v << ","; o << "]"; return o; } using ll = long long; constexpr ll MOD1 = 1e9; constexpr ll MOD2 = 1000000007; constexpr int MAX = 100000; int main() { string str; cin >> str; const int digit = str.size(); if (digit == 1) { cout << str << endl; return 0; } vector<int> digits(digit); rep(i, digit) { digits[i] = str[i] - '0'; } bool ispower = true; rep(i, digit) { if (i == 0) { if (digits[i] != 1) { ispower = false; break; } } else { if (digits[i] != 0) { ispower = false; break; } } } { ll num1 = 0; ll n = 1; for (int i = 1; i < digit; i++) { if (i % 2 == 1) { if (i == 1) { n = (n * 9) % MOD1; num1 = (num1 + n) % MOD1; } else { n = (n * 10) % MOD1; num1 = (num1 + n) % MOD1; } } else { num1 = (num1 + n) % MOD1; } } const int half = (digit - 1) / 2; bool flag = true; for (int i = half; i >= 0; i--) { if (digits[digit - i - 1] > digits[i]) { flag = true; break; } else if (digits[digit - i - 1] < digits[i]) { flag = false; } } ll num = 0; ll comp = 1; for (int i = 0; i <= half; i++) { if (i > 0) { comp = (comp * 10) % MOD1; } num = (num * 10) % MOD1; num = (num + digits[i]) % MOD1; } if (not flag) { num--; } cout << ((1 + num1 + num - comp) % MOD1 + MOD1) % MOD1 << endl; } { ll num2 = 0; ll n = 1; for (int i = 1; i < digit; i++) { if (i % 2 == 1) { if (i == 1) { n = (n * 9) % MOD2; num2 = (num2 + n) % MOD2; } else { n = (n * 10) % MOD2; num2 = (num2 + n) % MOD2; } } else { num2 = (num2 + n) % MOD2; } } const int half = (digit - 1) / 2; bool flag = true; for (int i = half; i >= 0; i--) { if (digits[digit - i - 1] > digits[i]) { flag = true; break; } else if (digits[digit - i - 1] < digits[i]) { flag = false; } } ll num = 0; ll comp = 1; for (int i = 0; i <= half; i++) { if (i > 0) { comp = (comp * 10) % MOD2; } num = (num * 10) % MOD2; num = (num + digits[i]) % MOD2; } if (not flag) { num--; } cout << ((1 + num2 + num - comp) % MOD2 + MOD2) % MOD2 << endl; } return 0; }