QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95001#6129. Magic Multiplication2000805113#AC ✓33ms4596kbC++172.7kb2023-04-08 16:59:022023-04-08 16:59:03

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-08 16:59:03]
  • 评测
  • 测评结果:AC
  • 用时:33ms
  • 内存:4596kb
  • [2023-04-08 16:59:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char c[N];
int n, m, K, a[N], b[N];
void solve() {
    scanf("%d%d", &n, &m);
    scanf("%s", c + 1);
    K = strlen(c + 1);
    if(c[1] == '0' && K == 1) {
        if(n == 1) {
            printf("0 ");
            if(m > 1) printf("1"), m--;
            for(int i = 1; i <= m; i++)
                printf("0");
            printf("\n");
        }else if(m == 1) {
            if(n > 1) printf("1"), n--;
            for(int i = 1; i <= n; i++)
                printf("0");
            printf(" 0\n");
        }else printf("Impossible\n");
        return;
    }
    for(int i = 1; i <= 9; i++) {
        a[1] = i;
        int flag = 1, k = 1;
        for(int j = 1; j <= m; j++, k++) {
            if(k > K) {flag = 0; break;}
            int sum = c[k] - 48;
            if(k < K && sum < i && sum != 0) k++, sum = sum * 10 + c[k] - 48;
            if(sum == 0 || sum % i == 0) b[j] = sum / i;
            else {
                flag = 0;
                break;
            }
        }
        if(!flag) continue;
    //    cout << i << " " << k << "\n";
        for(int j = 2; j <= n; j++) {
            if(k > K) {flag = 0; break;}
            int sum = c[k] - 48;
            if(k < K && sum < b[1] && sum != 0) k++, sum = sum * 10 + c[k] - 48;
            if(sum == 0 || sum % b[1] == 0) {
                a[j] = sum / b[1];
                k++;
                for(int mm = 2; mm <= m; mm++) {
                    if(k > K) {
                        flag = 0;
                        break;
                    }
                    sum = a[j] * b[mm];
                    if(sum < 10) {
                        if(sum == c[k] - 48) k++;
                        else {
                            flag = 0;
                            break;
                        }
                    }else {
                        if(sum / 10 == c[k] - 48 && sum % 10 == c[k + 1] - 48) k += 2;
                        else {
                            flag = 0;
                            break;
                        }
                    }
                }
                if(!flag) break;
            }else {
                flag = 0; 
                break;
            }
        }
        if(!flag || k <= K) continue;
        for(int i = 1; i <= n; i++)
            printf("%d", a[i]);
        printf(" ");
        for(int i = 1; i <= m; i++)
            printf("%d", b[i]);
        cout << "\n";
        return;
    }
    puts("Impossible");
}
int main() {
    int T; cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
/*
4
2 2
8101215
3 4
100000001000
2 2
80101215
3 4
1000000010000

*/

详细

Test #1:

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

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: 0
Accepted
time: 33ms
memory: 4596kb

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:

ok 1025 lines