QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93536#6129. Magic Multiplicationblack_iceWA 50ms5196kbC++144.6kb2023-04-01 11:21:112023-04-01 11:21:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-01 11:21:13]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:5196kb
  • [2023-04-01 11:21:11]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <array>
#include <iomanip>
using namespace std;
#define int long long
const int N = 1e5 + 10,INF = 1e17;
#define endl '\n'
int n,m,T;

void solve()
{
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> a;
    vector<int> b;
    int a1 = 0,pos = 0;
    bool flag = true;
    for(int a1 = 1;a1 <= 9;a1++)
    {
        a.clear();
        b.clear();
        pos = 0;
        a.push_back(a1);
        flag = true;
        while(pos < s.size() && b.size() < m)
        {
            int x = s[pos] - '0';
            if(x % a1 == 0 && x / a1 <= 9)
            {
                pos++;
                b.push_back(x / a1);
            }
            else{
                pos++;
                x = x * 10 + s[pos] - '0';
                if(x % a1 == 0 && x / a1 <= 9)
                {
                    pos++;
                    b.push_back(x / a1);
                }
                else{
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
        {
            if(b[0] == 0){
                flag = false;
                break;
            }
            else{
                int j = 0;
                while(pos < s.size() && a.size() <= n)
                {
                    int x = s[pos] - '0',t = 1;
                    if(!b[j] || (x % b[j] == 0 && x / b[j] <= 9))
                    {
                        pos++;
                        if(j == 0 || !t) 
                        {
                            if(b[j])
                                a.push_back(x / b[j]);
                            else{
                                if(x){
                                    flag = false;
                                    break;
                                }
                                else t = 1; 
                            }
                        }
                        else{
                            if(x && !b[j])
                            {
                                flag = false;
                                break;
                            }
                            else if(b[j] && a[a.size() - 1] != x / b[j])
                            {
                                flag = false;
                                break;
                            }
                        }
                    }
                    else{
                        pos++;
                        x = x * 10 + s[pos] - '0';
                        if(!b[j] || (x % b[j] == 0 && x / b[j] <= 9))
                        {
                            pos++;
                            if(j == 0 || !t) 
                            {
                                if(b[j])
                                    a.push_back(x / b[j]);
                                else{
                                    if(x){
                                        flag = false;
                                        break;
                                    }
                                    else t = 1; 
                                }
                            }
                            else{
                                if(x && !b[j])
                                {
                                    flag = false;
                                    break;
                                }
                                else if(b[j] && a[a.size() - 1] != x / b[j])
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        else{
                            flag = false;
                            break;
                        }
                    }
                    if(!t && j == m - 1)
                    {
                        flag = false;
                        break;
                    }
                    j = (j + 1) % m;
                }
                if(pos < s.size() || a.size() > n) flag = false;
            }
        }
        if(flag)
        {
            for(int i = 0;i < a.size();i++) cout << a[i];
            cout << ' ';
            for(int i = 0;i < b.size();i++) cout << b[i];
            cout << endl;
            return ;
        }
    }
    cout << "Impossible" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> T;
    while(T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3376kb

input:

4
2 2
8101215
3 4
100000001000
2 2
80101215
3 4
1000000010000

output:

23 45
101 1000
Impossible
Impossible

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 50ms
memory: 5196kb

input:

1025
11 18
1461416814188088414188241035153540203545200202010354520510254921495628496328028281449632871435351535402035452002020103545205102500000000000000000000000000004000000063276372366381360363618638136918454921495628496328028281449632871435492149562849632802828144963287143514614168141880884141882...

output:

Impossible
3583 5
161650357972 65354104569
597523997017 7693
Impossible
406723924695110 973937089831524
59331138450754 554
4 189401911962950
980565699171 84748728972992
Impossible
62155650672 4241405
9458752764004792353 8717596993614
Impossible
941952596 49242258343771276739
Impossible
64053045751 4...

result:

wrong answer 662nd lines differ - expected: '21 4', found: '1-1 8'