QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707322#2510. Make NumbersbecaidoAC ✓1ms3888kbC++202.0kb2024-11-03 15:29:322024-11-03 15:29:36

Judging History

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

  • [2024-11-03 15:29:36]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3888kb
  • [2024-11-03 15:29:32]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout<<"["<<#HEHE<<"] : ",dout(HEHE)
void dout(){cout<<'\n';}
template<typename T,typename...U>
void dout(T t,U...u){cout<<t<<(sizeof...(u)?", ":""),dout(u...);}
#else
#define debug(...) 7122
#endif

#define int long long
#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second

const int INF = 1e9;
const string str = "*+-";

void solve() {
    int a[4];
    FOR (i, 0, 3) cin >> a[i];
    set<int> s;
    sort (a, a + 4);
    do {
        FOR (mask, 1, 63) {
            vector<int> v;
            vector<char> c;
            int num = 0;
            int op[3];
            int x = mask;
            for (int j = 2; j >= 0; j--) op[j] = x % 4, x /= 4;
            FOR (i, 0, 3) {
                num = 10 * num + a[i];
                if (i == 3 || op[i] != 0) {
                    v.pb (num);
                    num = 0;
                }
                if (i < 3 && op[i] != 0) c.pb (str[op[i] - 1]);
            }
            vector<int> nv;
            vector<char> nc;
            num = -INF;
            FOR (i, 0, v.size() - 1) {
                if (num == -INF) num = v[i];
                else num *= v[i];
                if (i == v.size() - 1 || c[i] != '*') {
                    nv.pb (num);
                    if (i < c.size()) nc.pb (c[i]);
                    num = -INF;
                }
            }
            v = nv, c = nc;
            num = -INF;
            FOR (i, 0, v.size() - 1) {
                if (num == -INF) num = v[i];
                else if (c[i - 1] == '+') num += v[i];
                else num -= v[i];
            }
            if (num >= 0) s.insert (num);
        }
    } while (next_permutation (a, a + 4));
    cout << s.size() << '\n';
}

int32_t main() {
    Waimai;
    int tt = 1;
    while (tt--) solve();
}

詳細信息

Test #1:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

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

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

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

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

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

input:

2 2 4 4

output:

58

result:

ok single line: '58'

Test #8:

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

input:

2 3 4 5

output:

183

result:

ok single line: '183'

Test #9:

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

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

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

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

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

input:

2 5 5 5

output:

54

result:

ok single line: '54'

Test #12:

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

input:

2 8 6 4

output:

172

result:

ok single line: '172'

Test #13:

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

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

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

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

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

input:

5 7 8 9

output:

217

result:

ok single line: '217'

Test #16:

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

input:

9 9 9 9

output:

20

result:

ok single line: '20'