QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91040#6129. Magic MultiplicationyyyyxhWA 2ms3320kbC++171.1kb2023-03-26 20:18:492023-03-26 20:18:50

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:18:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3320kb
  • [2023-03-26 20:18:49]
  • 提交

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);
		cout<<ans.first<<' '<<ans.second<<endl;
	}
	return 0;
}

详细

Test #1:

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

input:

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

output:

23 45
101 1000
~ ~
200 5000

result:

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