QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639897 | #6129. Magic Multiplication | hhdhh | WA | 0ms | 3824kb | C++23 | 2.8kb | 2024-10-13 23:38:28 | 2024-10-13 23:38:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define endl '\n'
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define rept(i, a, ne) for(int i = (a); ~i ; i=ne[i])
#define debug(x) cout<<#x<<": "<<x<<endl
#define fi first
#define sec second
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int>PII;
const int N=2e5+10;
LL n,m;
int a[N],b[N];
string s;
LL len;
LL get(int x)
{
return s[x]-'0';
}
bool op(int x)
{
int n2=0;
rep(i,2,n)
a[i]=-1;
a[1]=x;
rep(i,1,len)
{
if(get(i)%x==0)
{
b[++n2]=get(i)/x;
}
else if(i!=len&&get(i)&&(get(i)*10+get(i+1))%x==0)
{
b[++n2]=(get(i)*10+get(i+1))/x;
i++;
}
else
return 0;
// debug(b[n2]);
if(n2==m)
break;
}
if(n2<m)
return 0;
int n1=0;
int p=0;
int sum=0;
rep(i,1,len)
{
if(sum>n*m)
return 0;
if(sum%n==0)
++n1;
++p;
if(b[p]==0)
{
if(get(i)!=0)
{
return 0;
}
}
else if(get(i)%b[p]==0)
{
if(a[n1]!=-1)
{
if(a[n1]!=get(i)/b[p])
return 0;
}
else
a[n1]=get(i)/b[p];
}
else if(i!=len&&get(i)&&(get(i)*10+get(i+1))%b[p]==0)
{
int y=(get(i)*10+get(i+1));
if(a[n1]!=-1)
{
if(a[n1]!=y/b[p])
return 0;
}
else
a[n1]=y/b[p];
i++;
}
else
return 0;
// debug(a[n1]);
// debug(i);
sum++;
p%=m;
}
if(sum!=n*m)
return 0;
return 1;
}
int pp=0;
void slove()
{
pp++;
cin>>n>>m;
cin>>s;
len=s.size();
if(pp==2)
{
debug(s);
}
s='0'+s;
if(len<n*m||len>n*m*2)
{
cout<<"Impossible"<<endl;
return;
}
rep(i,1,9)
{
if(op(i))
{
rep(i,1,n)
cout<<a[i];
cout<<' ';
rep(i,1,m)
cout<<b[i];
cout<<endl;
return;
}
}
cout<<"Impossible"<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// cout << fixed << setprecision(9);
int t=1;
cin>>t;
while(t--)
{
slove();
}
return 0;
}
//#pragma GCC optimize(2)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3824kb
input:
4 2 2 8101215 3 4 100000001000 2 2 80101215 3 4 1000000010000
output:
23 45 s: 100000001000 101 1000 Impossible Impossible
result:
wrong answer 2nd lines differ - expected: '101 1000', found: 's: 100000001000'