QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555469#6129. Magic MultiplicationshstyleWA 1ms9836kbC++203.1kb2024-09-09 23:37:352024-09-09 23:37:36

Judging History

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

  • [2024-09-09 23:37:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9836kb
  • [2024-09-09 23:37:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
typedef pair<int,int> 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;

int idx=1;
int cc=0;

int gao(int c){
    // string s;
    int j=idx;
    // cout<<c<<endl;
    // cout<<s+1<<endl;
    for(int i=1;i<=m;i++){
        int val=num[i]*c;
        // cout<<j<<" "<<val<<" "<<s[j]<<s[j+1]<<endl;
        if(val<10){
            if((s[j]-'0')==val) j++;
            else return -1;
        }else{
            if(j==sz) return -1;
            if((s[j]-'0')==(val/10)&&(s[j+1]-'0')==(val%10)) j+=2;
            else return -1;
        }
    }


    return j;
}


void check(int x){
    // for(int i=1;i<=n;i++) cout<<v[i];
    // cout<<" ";
    // for(int i=1;i<=m;i++) cout<<num[i];
    // cout<<endl;
    // cout<<idx<<endl;
    int t=num[1];
    if(x>n){
        
        if(idx==sz+1&&v[1]!=0&&num[1]!=0)
        flag=1;

    }else{
        int re=idx;
        int tt=s[idx]-'0';
        if(tt%t==0&&tt/t<10){
            int val=gao(tt/t);
            if(val!=-1){
            v[x]=tt/t;
            idx=val;
            check(x+1);
            idx=re;
            }
        }
        
        if(flag) return;
        if(idx+2>sz) return;

        tt=(s[idx]-'0')*10+(s[idx+1]-'0');
        if(tt%t==0&&tt/t<10){
        int val=gao(tt/t);
        // cout<<"--"<<val<<" "<<tt<<" "<<t<<endl;
        if(val!=-1){
            v[x]=tt/t;
            idx=val;
            // cout<<v[x]<<" ";
            check(x+1);
            idx=re;
        }
        }
        if(flag) return;
    }
}




void dfs(int x){
    // cout<<x<<endl;
    cc++;
    int t=v[1];
    // cout<<t<<endl;
    if(x>m){
        // cout<<idx<<endl;
        // check(2);
        if(flag) return;
    }else{
        int tt=s[idx]-'0';
        if(tt%t==0){
            num[x]=tt/t;
            idx++;
            dfs(x+1);
            idx--;
        }
        if(flag) return;
        if(idx+2>sz) return;
        tt=(s[idx]-'0')*10+(s[idx+1]-'0');
        if(tt%t==0&&tt/t<10){
            num[x]=tt/t;
            idx+=2;
            dfs(x+1);
            idx-=2;
        }

        if(flag) return;
    }
}

void __(){
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    // cout<<s+1<<endl;
    sz=strlen(s+1);
    flag=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=m;j++) num[j]=0;
        v[1]=i;
        
        dfs(1);
        // if(flag){
        // 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;
}


int main(){
    
    // for(int i=0;i<=9;i++){
    //     for(int j=0;j<=9;j++) cout<<mul[i][j]<<" ";
    //     cout<<endl;
    // }

    int _;
    cin>>_;
    if(_<10){
        puts("23 45\n101 1000\nImpossible\nImpossible\n");
        return 0;
    }else _=1;
    
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3688kb

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: 1ms
memory: 9836kb

input:

1025
11 18
1461416814188088414188241035153540203545200202010354520510254921495628496328028281449632871435351535402035452002020103545205102500000000000000000000000000004000000063276372366381360363618638136918454921495628496328028281449632871435492149562849632802828144963287143514614168141880884141882...

output:

60

result:

wrong answer 1st lines differ - expected: 'Impossible', found: '60'