QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721437#2510. Make Numbersucup-team5062#AC ✓0ms3828kbC++201.3kb2024-11-07 16:06:332024-11-07 16:06:33

Judging History

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

  • [2024-11-07 16:06:33]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3828kb
  • [2024-11-07 16:06:33]
  • 提交

answer

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

set<int> ans;

void pm(vector<int> a) {
    int n = (int)a.size() - 1;
    for (int s = 0; s < (1 << n); ++s) {
        int x = a[0];
        for (int i = 0; i < n; ++i) {
            if (s >> i & 1) {
                x += a[i + 1];
            } else {
                x -= a[i + 1];
            }
        }
        if (x >= 0) {
            ans.insert(x);
        }
    }
}

void mul(vector<int> a) {
    int n = (int)a.size() - 1;
    for (int s = 0; s < (1 << n); ++s) {
        vector<int> b;
        int x = 1;
        for (int i = 0; i <= n; ++i) {
            x *= a[i];
            if (i == n || (s >> i & 1)) {
                b.push_back(x);
                x = 1;
            }
        }
        pm(b);
    }
}

int main() {
    vector<int> a(4);
    for (auto& x : a) cin >> x;
    sort(a.begin(), a.end());
    do {
        for (int s = 1; s < 8; ++s) {
            vector<int> b;
            int x = 0;
            for (int i = 0; i < 4; i++) {
                x = 10 * x + a[i];
                if (i == 3 || (s >> i & 1)) {
                    b.push_back(x);
                    x = 0;
                }
            }
            mul(b);
        }
    } while (next_permutation(a.begin(), a.end()));
    cout << ans.size() << endl;
}

详细

Test #1:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

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

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

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

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

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

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: 3704kb

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

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

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

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

input:

2 5 5 5

output:

54

result:

ok single line: '54'

Test #12:

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

input:

2 8 6 4

output:

172

result:

ok single line: '172'

Test #13:

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

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

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

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

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

input:

5 7 8 9

output:

217

result:

ok single line: '217'

Test #16:

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

input:

9 9 9 9

output:

20

result:

ok single line: '20'