QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555466#6129. Magic MultiplicationshstyleCompile Error//C++203.2kb2024-09-09 23:34:542024-09-09 23:34:55

Judging History

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

  • [2024-09-09 23:34:55]
  • 评测
  • [2024-09-09 23:34:54]
  • 提交

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 cnt=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;
    cnt++;
    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((t==0&&tt==0)||(t!=0&&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(t!=0&&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;
        assert(idx==1);
        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 ;
        // }
    }
     puts("Impossible");
    cout<<cnt<<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

answer.code:20:5: error: conflicting declaration ‘int cnt’
   20 | int cnt=0;
      |     ^~~
answer.code:7:5: note: previous declaration as ‘int cnt [1000010]’
    7 | int cnt[N];
      |     ^~~
answer.code: In function ‘void dfs(int)’:
answer.code:94:5: error: lvalue required as increment operand
   94 |     cnt++;
      |     ^~~
answer.code: In function ‘void __()’:
answer.code:124:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  124 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
answer.code:125:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  125 |     scanf("%s",s+1);
      |     ~~~~~^~~~~~~~~~