QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101397#6129. Magic Multiplicationdiyitibu#WA 2ms5372kbC++202.0kb2023-04-29 14:21:232023-04-29 14:21:25

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

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){
	a[1] = x ;
	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 ++ ; 
		}
	}
	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+1)
		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 ++) {
			if(check(x)) {
				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: 5372kb

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'