QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581378#2510. Make NumbersCSQ#AC ✓1ms3860kbC++141.8kb2024-09-22 12:23:312024-09-22 12:23:32

Judging History

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

  • [2024-09-22 12:23:32]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3860kb
  • [2024-09-22 12:23:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size();
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
set<int>s;
void solve(vector<int>v,bool mode){
    int n = sz(v);
    if(n==1){
        s.insert(v[0]);
        return;
    }
    if(mode==1){
        vector<int>u;
        for(int i=0;i+1<n;i++){
            vector<int>u;
            for(int j=0;j<i;j++)u.push_back(v[j]);
            u.push_back(v[i]*v[i+1]);
            for(int j=i+2;j<n;j++)u.push_back(v[j]);
            solve(u,1);
            solve(u,0);
        }
    }else{
        for(int i=0;i<(1<<n);i++){
            if(i&1)continue;
            int sum = 0;
            for(int j=0;j<n;j++){
                if(i&(1<<j))sum -=v[j];
                else sum += v[j];
            }
            s.insert(sum);
        }
        return;
    }
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int a[4];
    for(int i=0;i<4;i++)cin>>a[i];
    vector<int>p = {0,1,2,3};
    while(true){
        vector<int>b(4);
        for(int i=0;i<4;i++)b[i] = a[p[i]];

        solve(b,1);
        solve(b,0);
        vector<int>c = {10*b[0]+b[1],b[2],b[3]};
        solve(c,1);
        solve(c,0);
        c = {b[0],b[1],10*b[2]+b[3]};
        solve(c,1);
        solve(c,0);
        c = {10*b[0]+b[1],10*b[2]+b[3]};
        solve(c,1);
        solve(c,0);


        c = {100*b[0]+10*b[1]+b[2],b[3]};
        solve(c,1);
        solve(c,0);
        c = {b[0],100*b[1]+10*b[2]+b[3]};
        solve(c,1);
        solve(c,0);
        if(!next_permutation(all(p)))break;
    }
    int ans = 0;
    for(int x:s)ans+=x>=0;
    cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

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

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

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

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

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

input:

2 2 4 4

output:

58

result:

ok single line: '58'

Test #8:

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

input:

2 3 4 5

output:

183

result:

ok single line: '183'

Test #9:

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

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

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

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

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

input:

2 5 5 5

output:

54

result:

ok single line: '54'

Test #12:

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

input:

2 8 6 4

output:

172

result:

ok single line: '172'

Test #13:

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

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

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

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

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

input:

5 7 8 9

output:

217

result:

ok single line: '217'

Test #16:

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

input:

9 9 9 9

output:

20

result:

ok single line: '20'