QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718080#2510. Make Numbersyuto1115#AC ✓1ms3824kbC++201.2kb2024-11-06 19:38:392024-11-06 19:38:39

Judging History

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

  • [2024-11-06 19:38:39]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3824kb
  • [2024-11-06 19:38:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep2(i,j,k) for(ll i = ll(j); i < ll(k); i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i = ll(j)-1; i >= ll(k); i--)
#define rrep(i,k) rrep2(i,k,0)
#define all(a) a.begin(), a.end()
#define SZ(a) ll(a.size())
#define eb emplace_back
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
const ll inf = LLONG_MAX/4;
bool chmin(auto& a, auto& b) {return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, auto& b) {return a < b ? a = b, 1 : 0; }

vl f(vl v) {
	int n = SZ(v);
	vl res;
	auto g = [&](auto &g, int i, ll val) -> void {
		if(i == n) {
			res.eb(val);
			return;
		}
		ll now = 1;
		rep2(j,i,n) {
			now *= v[j];
			g(g,j+1,val+now);
			g(g,j+1,val-now);
		}
	};
	g(g, 0, 0);
	return res;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	vl v(4);
	rep(i, 4) cin >> v[i];
	set<ll> st;
	vl ord(4);
	iota(all(ord), 0);
	do {
	rep(b, 7) {
		vl a;
		a.eb(v[ord[0]]);
		rep(i, 3) {
			if(b>>i&1) {
				a.back() = a.back() * 10 + v[ord[i+1]];
			} else {
				a.eb(v[ord[i+1]]);
			}
		}
		for(ll j : f(a)) if(j >= 0) st.insert(j);
	}
	} while(next_permutation(all(ord)));
	cout << st.size() << endl;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

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

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

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

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

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

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

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

input:

2 2 4 4

output:

58

result:

ok single line: '58'

Test #8:

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

input:

2 3 4 5

output:

183

result:

ok single line: '183'

Test #9:

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

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

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

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

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

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

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

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

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

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

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'