結果

問題 No.539 インクリメント
ユーザー xuzijian629xuzijian629
提出日時 2018-10-31 14:23:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 11,776 ms
コンパイル使用メモリ 455,084 KB
実行使用メモリ 40,832 KB
最終ジャッジ日時 2024-04-30 01:31:49
合計ジャッジ時間 16,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 235 ms
35,328 KB
testcase_02 TLE -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

int main() {
    int n;
    cin >> n;
    regex re("^(\\D*)(\\d+)(.*)$"), re2("^(0*)([1-9]\\d*)$");
    string s;
    getline(cin, s);
    while (n--) {
        getline(cin, s);
        reverse(s.begin(), s.end());
        smatch m;
        if (regex_search(s, m, re)) {
            string t = "";
            string u = m[3];
            reverse(u.begin(), u.end());
            t += u;
            u = m[2];
            reverse(u.begin(), u.end());
            smatch m2;
            if (regex_search(u, m2, re2)) {
                string m21 = m2[1], m22 = m2[2];
                mp::cpp_int x(m22);
                x++;
                if (m21.size() == 0) {
                    t += x.str();
                } else {
                    if (m22.size() == x.str().size()) {
                        t += m21;
                        t += x.str();
                    } else {
                        assert(m22.size() + 1 == x.str().size());
                        t += m21.substr(0, m21.size() - 1);
                        t += x.str();
                    }
                }
            } else {
                t += u.substr(0, u.size() - 1);
                t += '1';
            }
            u = m[1];
            reverse(u.begin(), u.end());
            t += u;
            cout << t << endl;
        } else {
            reverse(s.begin(), s.end());
            cout << s << endl;
        }
    }
}
0