QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588639#6407. Classical A+B ProblemTobo#RE 0ms3772kbC++202.9kb2024-09-25 13:49:122024-09-25 13:49:12

Judging History

你现在查看的是最新测评结果

  • [2024-09-25 13:49:12]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3772kb
  • [2024-09-25 13:49:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;

        int n = s.length();
        vector<int> pos{0};
        for (int i = 1; i < n; i++)
            if (s[i] != s[i - 1])
                pos.push_back(i);

        auto check = [&](string &x, string &y) -> bool
        {
            if (x.length() < y.length())
                return false;
            if (x.length() > y.length())
                return true;
            if (x.length() == y.length())
            {
                for (int i = 0; i < x.length(); i++)
                {
                    if (x[i] == y[i])
                        continue;
                    if (x[i] > y[i])
                        return true;
                    else
                        return false;
                }
            }
            return true;
        };
        auto minus = [&](string x, string y) -> string
        {
            string res;
            int flag = 0;
            while (!x.empty() or !y.empty())
            {
                int cur = flag;
                flag = 0;
                if (!x.empty())
                {
                    cur += x.back() - '0';
                    x.pop_back();
                }
                if (!y.empty())
                {
                    cur -= y.back() - '0';
                    y.pop_back();
                }
                if (cur < 0)
                {
                    flag = -1;
                    cur += 10;
                }
                res.push_back(char('0' + cur));
            }
            while (res.back() == '0')
                res.pop_back();
            assert(flag == 0);
            reverse(res.begin(), res.end());
            return res;
        };
        auto check1 = [&](string &s) -> bool
        {
            if (s == "0" or s.empty())
                return false;
            for (int i = 1; i < s.length(); i++)
                if (s[i] != s[0])
                    return false;
            return true;
        };

        bool done = false;
        for (int x : pos)
        {
            if (done)
                break;
            for (int i = 1; i <= 9 and !done; i++)
            {
                string cur = string(n - x, char('0' + i));
                if (check(s, cur))
                {
                    string res = minus(s, cur);
                    if (check1(res))
                    {
                        cout << cur << ' ' << res << '\n';
                        done = true;
                        break;
                    }
                }
            }
        }
        assert(done);
    }
}
/*
6
2
786
1332
89110
2333333
10000000000000000000000000001
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

1 1
777 9
333 999
88888 222
2222222 111111
9999999999999999999999999999 2

result:

ok ok (6 test cases)

Test #2:

score: -100
Runtime Error

input:

100
854
77777777781111111111111111110
44444450
11111111111111333
2310
5
333333333333333333333343332
888999
10
11113333
335
77779
88888888888888888888889111111111111111111110
55555555555555777777
72222222222222222222221
666
5777
1111555555
444444444544444444443
88888888888891111111111110
673332
97
77...

output:


result: