結果

問題 No.491 10^9+1と回文
ユーザー sekiya9311sekiya9311
提出日時 2017-03-10 23:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,207 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 113,448 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-06 14:40:58
合計ジャッジ時間 4,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

LL n;
const LL num = 1e9 + 1;

int main() {
    cin >> n;
    if (n < num) {
        cout << 0 << endl;
        return 0;
    }
    LL high = 1e9 + 10, low = 0;
    while (high - low > 1) {
        const LL mid = (high + low) / 2;
        if (num * mid <= n) low = mid;
        else high = mid;
    }
    LL cnt = low;
    LL ans = 0;
    if (cnt < 10) {
        cout << cnt << endl;
        return 0;
    }
    REP(i, to_string(low).size()) {
        if (i + 1 != to_string(low).size()) ans += 9 * pow(10, i / 2);
        else {
            LL nn = powl(10, ((int)to_string(low).size() - 1) / 2);
            LL ma = nn * 10;
            while (true) {
                string str = to_string(nn);
                string strbuf = str;
                REVERSE(strbuf);
                strbuf = str + strbuf;
                if (low >= stoll(strbuf)) ++ans;
                ++nn;
                if (nn == ma) break;
            }
            nn = ma / 10;
            while (true) {
                string str = to_string(nn);
                string strbuf = str;
                REVERSE(strbuf);
                REP(i, 10) {
                    string strbuf2 = str + (char)(i + '0') + strbuf;
                    //DEBUG(strbuf2)
                    if (low >= stoll(strbuf2)) ++ans;
                }
                ++nn;
                if (nn == ma) break;
            }
            break;
        }
    }
    high = 1e9 + 10, low = 0;
    cout << ans << endl;
}
0