QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654093 | #6129. Magic Multiplication | ucup-team5217# | WA | 17ms | 5692kb | C++23 | 1.9kb | 2024-10-18 21:04:53 | 2024-10-18 21:05:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define maxn 200005
int s[maxn], a[maxn], b[maxn];
void solve(void) {
int n, m;
cin >> n >> m;
string sss;
cin >> sss;
int len = sss.size();
for (int i = 1; i <= len; i++) s[i] = sss[i - 1] - '0';
for (a[1] = 1; a[1] <= 9; a[1]++) {
bool chk = true;
int p = 1;
for (int j = 1; j <= m && chk; j++)
if (p <= len && s[p] % a[1] == 0)
b[j] = s[p] / a[1], p++;
else if (p + 1 <= len && (s[p] * 10 + s[p + 1]) % a[1] == 0)
b[j] = (s[p] * 10 + s[p + 1]) / a[1], p += 2;
else
chk = false;
if (!chk) continue;
for (int i = 2; i <= n && chk; i++) {
a[i] = -1;
for (int j = 1; j <= m && chk; j++) {
if (!b[j]) {
if (p <= len && s[p] == 0)
p++;
else
chk = false;
continue;
}
int v = -1;
if (p <= len && s[p] % b[j] == 0)
v = s[p] / b[j], p++;
else if (p + 1 <= len && (s[p] * 10 + s[p + 1]) % b[j] == 0)
v = (s[p] * 10 + s[p + 1]) / b[j], p += 2;
else
chk = false;
if (a[i] == -1) a[i] = v;
if (a[i] != v) chk = false;
}
}
if (!chk || p != len + 1) continue;
for (int i = 1; i <= n; i++) cout << a[i];
cout << ' ';
for (int i = 1; i <= m; i++) cout << b[i];
cout << endl;
return;
}
cout << "Impossible" << endl;
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
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: 17ms
memory: 5692kb
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 119th lines differ - expected: '9 9691352', found: '3 27182739156'