QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91041#6129. Magic MultiplicationyyyyxhWA 2ms3272kbC++171.2kb2023-03-26 20:19:532023-03-26 20:19:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 20:19:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3272kb
  • [2023-03-26 20:19:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
string s;
int n,m,len;
pair<string,string> ans;
void decode(int x){
	string a="",b="";
	a+=x^48;
	int pos=0;
	for(int i=0;i<len;++i){
		int c=s[i]^48;
		if(c%x){
			if(i==len-1) return;
			c=(c<<1)+(c<<3)+(s[++i]^48);
		}
		if(c%x) return;
		if(c/x>9) return;
		b+=(c/x)^48;
		if(int(b.length())==m){pos=i;break;}
	}
	if(int(b.length())<m) return;
	int p=0;
	bool all0=1;
	for(int i=pos+1;i<len;++i){
		int c=s[i]^48;
		int bp=b[p]^48;
		if(bp){
			if(c%bp){
				if(i==len-1) return;
				c=(c<<1)+(c<<3)+(s[++i]^48);
			}
			if(c%bp) return;
			if(c/bp>9) return;
			if(!p||all0) a+=(c/bp)^48;
			else{if(a.back()!=((c/bp)^48)) return;}
			all0=0;
		}
		++p;
		if(p==m){
			if(all0) a+=48;
			p=0;all0=1;
		}
		if(int(a.length())>n) return;
	}
	if(int(a.length())<n) return;
	ans=min(ans,make_pair(a,b));
}
int main(){
	ios::sync_with_stdio(0);
	int tc;
	cin>>tc;
	while(tc--){
		cin>>n>>m>>s;
		ans=make_pair("~","~");len=s.length();
		for(int i=1;i<=9;++i) decode(i);
		if(ans.first=="~") cout<<"Impossible"<<endl;
		else cout<<ans.first<<' '<<ans.second<<endl;
	}
	return 0;
}

詳細信息

Test #1:

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

input:

4
2 2
8101215
3 4
100000001000
2 2
80101215
3 4
1000000010000

output:

23 45
101 1000
Impossible
200 5000

result:

wrong answer 4th lines differ - expected: 'Impossible', found: '200 5000'