QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326173#2510. Make NumbersRabeya#AC ✓1ms3808kbC++233.0kb2024-02-12 14:54:052024-02-12 14:54:05

Judging History

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

  • [2024-02-12 14:54:05]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3808kb
  • [2024-02-12 14:54:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
#define case cout<<"Case "<<__testcase-testcase<<":";
//#define endl '\n'
vii operating(vii a){
    int n=a.size();
    int ans=a[0];
    int last=a[0];
    vii ret;
    int k;
    //for(auto i: a) cout<<i<<" "; cout<<endl;
    for(int m=0;m<(1<<(2*n-2));m++){
        for(k=0;k<2*n-2;k+=2) if((m&(3<<k))==0) break;
        if(k<2*n-2) continue;
        //cout<<(m&3)<<" "<<((m&12)/4)<<" "<<((m&48)/16)<<endl;
        for(int i=0;i<2*n-2;i+=2){
            //cout<<" "<<ans<<endl;
            if(((m&(3<<i))>>i)==1){
                ans-=a[i/2+1];
                last=-a[i/2+1];
            }
            else if(((m&(3<<i))>>i)==2){
                ans+=a[i/2+1];
                last=a[i/2+1];
            }
            else if(((m&(3<<i))>>i)==3){
                ans=ans-last+last*a[i/2+1];
                last*=a[i/2+1];
            }
        }
        //cout<<ans<<endl;
        if(ans>=0) ret.pb(ans);
        ans=a[0];
        last=a[0];
    }
    //for(auto i: ret) cout<<" "<<i; cout<<endl; cout<<endl;
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    int __testcase=testcase;
    //operating({1,1,1,1});
    while(testcase--)
    {
        int n,m,i,j,k,l,r;
        vii d(4); for(auto &i: d) cin>>i;
        vii ans;
        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if(j==i) continue;
                for(k=0;k<4;k++){
                    if(k==j || k==i) continue;
                    for(l=0;l<4;l++){
                        if(l==i || l==j ||l==k) continue;
                        vii t(4);
                        t[i]=d[0];
                        t[j]=d[1];
                        t[k]=d[2];
                        t[l]=d[3];
                        for(m=1;m<8;m++){
                            vii x;
                            int y=t[0];
                            for(r=0;r<3;r++){
                                if(m&(1<<r)){x.pb(y); y=t[r+1];}
                                else y=10*y+t[r+1];
                            }
                            x.pb(y);
                            //for(auto i: x) cout<<i<<" "; cout<<endl; cout<<endl;
                            vii ret=operating(x);
                            for(auto i: ret) ans.pb(i);
                        }
                    }
                }
            }
        }
        sort(ans.begin(),ans.end());
        //cout<<ans[0]<<endl;
        int cnt=1;
        for(i=1;i<ans.size();i++) if(ans[i]!=ans[i-1]){ cnt++;};
        cout<<cnt<<endl;
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3612kb

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

2 2 4 4

output:

58

result:

ok single line: '58'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

2 3 4 5

output:

183

result:

ok single line: '183'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2 5 5 5

output:

54

result:

ok single line: '54'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2 8 6 4

output:

172

result:

ok single line: '172'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

5 7 8 9

output:

217

result:

ok single line: '217'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

9 9 9 9

output:

20

result:

ok single line: '20'