QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101394 | #6129. Magic Multiplication | diyitibu# | WA | 2ms | 5416kb | C++20 | 2.3kb | 2023-04-29 13:57:35 | 2023-04-29 13:57:36 |
Judging History
answer
#include <iostream>
#include <bits/stdc++.h>
#define int long long
using namespace std ;
const int N = 1e6 +10 ;
int read(){
int res = 0 , flag = 1 ;
char c = getchar() ;
while(!isdigit(c)) {
if(c == '-') flag = -1 ;
c = getchar() ;
}
while(isdigit(c)) {
res = (res <<1) +(res <<3)+(c ^48) ;
c = getchar() ;
}
return res *flag ;
}
void write(int x){
if(x < 0) {
putchar('-') ;
x = -x ;
}
if(x >= 10) write(x / 10) ;
putchar('0' +x %10) ;
}
void write(int x , char c){
write(x) ;
putchar(c) ;
}
int a[N] , b[N] ;
int n , m ;
int M ;
string s ;
bool check(int x , int y){
a[1] = x , b[1] = y ;
int j = 1 ;
for(int i = 1 ; i <= m ; i ++) {
if(j > M) return false ;
int f = s[j] - '0' ;
if(f % x == 0) {
j ++ ;
b[i] = f / x ;
}
else {
j ++;
if(j > M) return false ;
f = f * 10 + s[j] - '0' ;
if(f % x) return false ;
b[i] = f / x ;
j ++ ;
}
}
if(b[1] != y) return false ;
for(int i = 2 ; i <= n ; i ++) {
if(j > M) return false ;
int f = s[j] - '0' ;
if(f % b[1] == 0) a[i] = f / b[1] , j ++;
else {
j ++ ;
if(j > M) return false ;
f = f * 10 + s[j] - '0' ;
if(f % b[1]) return false;
a[i] = f / b[1] ;
j ++ ;
}
for(int k = 2 ; k <= m ; k ++) {
int f = a[i] * b[k] ;
if(j > M) return false ;
int g = s[j] - '0' ;
j ++ ;
if(f >= 10) {
if(j > M) return false ;
g = g * 10 + s[j] - '0' ;
j ++ ;
}
if(g != f) return false ;
}
}
if(j > M)
return true ;
else return false ;
}
void solve(){
n = read() , m = read() ;
cin >> s ;
M = s.size() ;
s = " " + s;
for(int x = 1 ; x <= 9 ; x ++) {
for(int y = 1 ; y <= 9 ; y ++) {
int f = s[1] - '0' ;
if(f == x * y && check(x , y)) {
for(int i = 1 ; i <= n ; i ++) write(a[i]) ;
puts("") ;
for(int i = 1 ; i <= m ; i ++) write(b[i]) ;
puts("") ;
return ;
}
if(M >= 2) {
int g = f * 10 + s[2] - '0' ;
if(g == x * y && check(x , y)) {
for(int i = 1 ; i <= n ; i ++) write(a[i]) ;
puts("") ;
for(int i = 1 ; i <= m ; i ++) write(b[i]) ;
puts("") ;
return ;
}
}
}
}
puts("Impossible") ;
}
signed main(void) {
int T ;
cin >>T;
while(T --) {
solve();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5416kb
input:
4 2 2 8101215 3 4 100000001000 2 2 80101215 3 4 1000000010000
output:
23 45 101 1000 Impossible Impossible
result:
wrong answer 1st lines differ - expected: '23 45', found: '23'