QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252602 | #6129. Magic Multiplication | sfjh | WA | 1ms | 5752kb | C++14 | 2.2kb | 2023-11-15 22:16:35 | 2023-11-15 22:16:36 |
Judging History
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++;
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(a[cnt1]==0&&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++;
}
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();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5752kb
input:
4 2 2 8101215 3 4 100000001000 2 2 80101215 3 4 1000000010000
output:
1 8 num1 1 2 8 num1 1 23 45 1 1 num1 1 impossible 1 8 num1 2 8 num1 4 8 num1 8 8 num1 impossible 1 1 num1 1 impossible
result:
wrong answer 1st lines differ - expected: '23 45', found: '1 8 num1'