QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555482 | #6129. Magic Multiplication | shstyle | WA | 176ms | 53332kb | C++20 | 4.0kb | 2024-09-10 00:14:35 | 2024-09-10 00:14:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int N=2e6+10;
const int seed1=131,mod1=1e9+7;
const int seed2=13331,mod2=998244353;
typedef pair<ll,ll> PII;
int w[N];
int cnt[N];
vector<int> pp;
bool tf[N];
int n,m;
int mul[15][15];
int v[N];
int num[N];
char s[N];
int sz;
bool flag=0;
PII hx[N];
PII hsh[N];
ll len[N];
int idx=1;
int cc=0;
PII mi[N];
PII gethash(int l,int r){
// if(l==1){
// cout<<l<<" "<<r<<endl;
// cout<<hsh[r].first<<" "<<hsh[l-1].first<<" "<<mi[r-l+1].first<<endl;
// }
ll num1=(hx[r].first-hx[l-1].first*mi[r-l+1].first)%mod1;
num1=(num1+mod1)%mod1;
ll num2=(hx[r].second-hx[l-1].second*mi[r-l+1].second)%mod2;
num2=(num2+mod2)%mod2;
// if(l==1)
// cout<<num1<<" "<<num2<<endl;
return {num1,num2};
}
bool match(){
for(int i=0;i<=9;i++){
string ss;
for(int j=1;j<=m;j++){
int ts=i*num[j];
ss+=to_string(ts);
}
// cout<<s<<endl;
PII res={0,0};
for(int j=0;j<ss.size();j++){
ll res1=res.first*seed1+ss[j];
ll res2=res.second*seed2+ss[j];
res1%=mod1;
res2%=mod2;
res={res1,res2};
}
hsh[i]=res;
len[i]=ss.size();
}
int j=1;
for(int i=1;i<=n;i++){
bool flag=0;
for(int k=9;k>=0;k--){
// if(num[1]==4){
// // cout<<i<<endl;
// cout<<j<<" "<<j+len[k]-1<<endl;
// cout<<"-----"<<gethash(j,j+len[k]-1).first<<" "<<gethash(j,j+len[k]-1).second<<endl;
// cout<<hsh[k].first<<" "<<hsh[k].second<<endl;
// }
if(j+len[k]-1<=sz&&gethash(j,j+len[k]-1)==hsh[k]){
v[i]=k;
j+=len[k];
flag=1;
break;
}
}
if(!flag) return false;
}
if(j==sz+1)
return true;
else return false;
// if()
}
void __(){
scanf("%lld%lld",&n,&m);
scanf("%s",s+1);
// cout<<s+1<<endl;
sz=strlen(s+1);
flag=0;
for(int i=1;i<=sz;i++){
hx[i].first=(hx[i-1].first*seed1+s[i])%mod1;
hx[i].second=(hx[i-1].second*seed2+s[i])%mod2;
// cout<<hsh[i].first<<" "<<hsh[i].second<<endl;
}
for(int i=1;i<=9;i++){
for(int j=1;j<=m;j++) num[j]=0;
v[1]=i;
bool ff=0;
idx=1;
for(int j=1;j<=m;j++){
int t1=s[idx]-'0';
if(t1%i==0){
num[j]=t1/i;
idx++;
}else{
if(s[idx]==sz){
ff=1;
break;
}
int t2=s[idx+1]-'0';
int tt=t1*10+t2;
// cout<<"--"<<tt<<endl;
if(tt%i==0&&tt/i<10){
num[j]=tt/i;
idx+=2;
}else {
ff=1;
break;
}
}
}
if(!ff){
// for(int j=1;j<=m;j++) cout<<num[j]<<" ";
// cout<<endl;
if(match()){
for(int i=1;i<=n;i++) printf("%d",v[i]);
printf(" ");
for(int i=1;i<=m;i++) printf("%d",num[i]);
printf("\n");
return ;
}
}
}
// cout<<cc<<endl;
puts("Impossible");
}
signed main(){
// for(int i=0;i<=9;i++){
// for(int j=0;j<=9;j++) cout<<i*j<<" ";
// cout<<endl;
// }
mi[0]={1,1};
for(int i=1;i<N;i++){
mi[i].first=mi[i-1].first*seed1%mod1;
mi[i].second=mi[i-1].second*seed2%mod2;
}
int _;
cin>>_;
// if(_<10){
// puts("23 45\n101 1000\nImpossible\nImpossible\n");
// return 0;
// }else _=1;
while(_--){
__();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 46712kb
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: 176ms
memory: 53332kb
input:
1025 11 18 1461416814188088414188241035153540203545200202010354520510254921495628496328028281449632871435351535402035452002020103545205102500000000000000000000000000004000000063276372366381360363618638136918454921495628496328028281449632871435492149562849632802828144963287143514614168141880884141882...
output:
Impossible 3583 5 161650357972 65354104569 597523997017 7693 Impossible 406723924695110 973937089831524 59331138450754 554 4 189401911962950 980565699171 84748728972992 Impossible 62155650672 4241405 9458752764004792353 8717596993614 Impossible 941952596 49242258343771276739 Impossible 64053045751 4...
result:
wrong answer 202nd lines differ - expected: '911204 607387', found: 'Impossible'