1 solutions

  • 0
    @ 2025-11-5 16:30:59

    C++ :

    #include <iostream>
    
    using namespace std;
    int a[100],ifHave[10];
    
    int main(){
        int n;
        cin>>n;
        for (int i=1;i<=n;i++){
            cin>>a[i];
            ifHave[a[i]]=1;
        }
        int ans=0;
        for (int a1=1;a1<=n;a1++)
            for (int a2=1;a2<=n;a2++)
                for (int a3=1;a3<=n;a3++)
                    for (int b1=1;b1<=n;b1++)
                        for (int b2=1;b2<=n;b2++){
                            int c11=a[a1]*a[b1],c12=a[a2]*a[b1],c13=a[a3]*a[b1],c21=a[a1]*a[b2],c22=a[a2]*a[b2],c23=a[a3]*a[b2];
                            c12+=c11/10;
                            c13+=c12/10;
                            c11%=10;
                            c12%=10;
                            if (c13>10)continue;
                            c22+=c21/10;
                            c23+=c22/10;
                            c21%=10;
                            c22%=10;
                            if (c23>10)continue;
                            if (ifHave[c11] && ifHave[c12] && ifHave[c13] && ifHave[c21] && ifHave[c22] && ifHave[c23] && (c13+c22+(c12+c21)/10)/10+c23<10)
                                if (ifHave[(c12+c21)%10] && ifHave[(c13+c22+(c12+c21)/10)%10] && ifHave[(c13+c22+(c12+c21)/10)/10+c23]) ans++;
                        }
        cout<<ans<<endl;
    }
    
    

    Pascal :

    var num:array[0..9]of boolean;
        a,now:array[1..10]of longint;
        i,n,ans:longint;
    function judge2(x:longint):boolean;
    var s:string;
        i:longint;
    begin
      str(x,s);
      for i:=1 to length(s) do
      if not num[ord(s[i])-48] then exit(false);
      exit(true);
    end;
    procedure judge;
    var i,x,y,k1,k2,k3:longint;
    begin
      x:=now[1]*100+now[2]*10+now[3];
      y:=now[4]*10+now[5];
      k1:=now[5]*x;
      k2:=now[4]*x;
      k3:=x*y;
      if(k1>999)or(k2>999)or(k3>9999)then exit;
      if(judge2(k1))and(judge2(k2))and(judge2(k3))then inc(ans);
    end;
    procedure dfs(x:longint);
    var i:longint;
    begin
      if x=6 then
      begin
        judge;
        exit;
      end;
      for i:=1 to n do
      begin
        if(a[i]=0)and((x=1)or(x=4))then continue;
        now[x]:=a[i];
        dfs(x+1);
      end;
    end;
    begin
      read(n);
      for i:=1 to n do
      begin
        read(a[i]);
        num[a[i]]:=true;
      end;
      dfs(1);
      write(ans);
    end.
    
    • 1

    Information

    ID
    17820
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By