QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101395#6129. Magic Multiplicationdiyitibu#WA 2ms5388kbC++202.4kb2023-04-29 14:02:272023-04-29 14:02:29

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-29 14:02:29]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5388kb
  • [2023-04-29 14:02:27]
  • 提交

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 ;
			if(b[i] >= 10) return false ; 
			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 ++ ; 
		}
		if(a[i] >= 10) return false ;
		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(); 
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5388kb

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'