QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252822#6129. Magic MultiplicationsfjhWA 9ms6752kbC++142.3kb2023-11-16 12:45:362023-11-16 12:45:36

Judging History

你现在查看的是最新测评结果

  • [2023-11-16 12:45:36]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:6752kb
  • [2023-11-16 12:45:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i>=b;i--)
const int N=2e5+10;

int n,m;
string s;
bool f;
int a[N],b[N]; 

bool cal(int x,int num){
	int cnt1=0,cnt2=0;
	int bgn=1,end=0;
	if(num>=10) bgn=2;
	for(int i=bgn;i<s.size();i++){
		if(cnt2==m-1){
			end=i;
			break;
		}
		int ff=0;
		int num1,num2;
		num1=s[i]-'0';
		if(i+1<s.size()) num2=(s[i]-'0')*10+s[i+1]-'0';
//		(i+1>=s.size()||s[i+1]!='0')
		if(num1%a[0]==0) b[++cnt2]=num1/a[0],ff=1;
		else if(num2%a[0]==0&&num2/a[0]<10&&i+1<s.size()) b[++cnt2]=num2/a[0],i++,ff=1; 
		if(!ff) return false;
	}
//	fer(i,0,cnt2) cout<<b[i];
//	cout<<"b"<<end<<endl;

	if(cnt2!=m-1) return false;
	int i=end;
//	cout<<cnt1<<endl;
	for(int k=1;k<n;k++){
		int ff=0;
		int num1,num2;
		num1=s[i]-'0';
		if(i+1<s.size()) num2=(s[i]-'0')*10+s[i+1]-'0';
		if(num1%b[0]==0) a[++cnt1]=num1/b[0],ff=1;
		else if(num2%b[0]==0&&num2/b[0]<10&&i+1<s.size()) a[++cnt1]=num2/b[0],i++,ff=1;
		i++;
//		cout<<a[cnt1]<<' '<<ff<<endl; 
		if(!ff) return false;
		for(int j=1;j<m;j++){
			ff=0;
			if(i>=s.size()) return false;
			num1=s[i]-'0';
			if(i+1<s.size()) num2=(s[i]-'0')*10+s[i+1]-'0';
			if(b[j]==0){
				if(num1==0){
					ff=1;
				}
			}
			else if(num1%b[j]==a[cnt1]) ff=1;
			else if(num2%b[j]==0&&num2/b[j]<10&&i+1<s.size()) ff=1,i++;
			if(!ff) return false;
			i++; 
		}
//		fer(l,0,cnt1) cout<<a[l];
//		cout<<endl;
//		cout<<cnt1<<endl;
	}
	 
	if(i!=s.size()) return false;
	if(cnt1!=n-1) return false;
	return true;
}

bool judge(int x,int num){
	if(num%x==0&&num/x<10){
		a[0]=x;
		b[0]=num/x;
		return true;
	}
	return false;
}

void solve(){
	cin>>n>>m;
	f=0;
	cin>>s;
	int num1=s[0]-'0';
	int num2=(s[0]-'0')*10+s[1]-'0';
	fer(i,1,9){
		if(judge(i,num1)){
//			cout<<i<<' '<<num1<<" num1\n";
			if(cal(i,num1)){
				f=1;
				break;
			}	
		}
		else if(judge(i,num2)){
//			cout<<i<<' '<<num2<<" num2\n";
			if(cal(i,num2)){
				f=1;
				break;
			}
		}
	}
	if(f){
		fer(i,0,n-1) cout<<a[i];
		cout<<' ';
		fer(i,0,m-1) cout<<b[i];
		cout<<endl;
	}
	else cout<<"Impossible\n";
}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
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: -100
Wrong Answer
time: 9ms
memory: 6752kb

input:

1025
11 18
1461416814188088414188241035153540203545200202010354520510254921495628496328028281449632871435351535402035452002020103545205102500000000000000000000000000004000000063276372366381360363618638136918454921495628496328028281449632871435492149562849632802828144963287143514614168141880884141882...

output:

Impossible
3583 5
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
26838140969 1
Impossible
Impossible
Impossible
Impossible
9677 389
Impossible
Impossible
3034637 9779895
Impossible
I...

result:

wrong answer 3rd lines differ - expected: '161650357972 65354104569', found: 'Impossible'