Skip to content

Commit fe86b45

Browse files
Merge pull request encrypted-def#255 from SciEm/14888_1.cpp
Update 14888_1.cpp
2 parents e5c527b + 45a956b commit fe86b45

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

0x0D/solutions/14888_1.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Authored by : SciEm
2+
// Co-authored by : -
3+
// http://boj.kr/d1e716682fbe499881cd32ec1c235f7e
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
int nums[12];
8+
int ops[12]; // ops[0]은 항상 더하기
9+
int n;
10+
int mn = 0x7f7f7f7f, mx = -0x7f7f7f7f;
11+
12+
int main() {
13+
ios::sync_with_stdio(0);
14+
cin.tie(0);
15+
16+
cin >> n;
17+
for (int i = 0; i < n; i++)
18+
cin >> nums[i];
19+
for (int op = 0, idx = 1; op < 4; op++) {
20+
int x; cin >> x;
21+
while (x--)
22+
ops[idx++] = op;
23+
}
24+
25+
do {
26+
int res = 0;
27+
for (int i = 0; i < n; i++) {
28+
if (ops[i] == 0) res += nums[i];
29+
else if (ops[i] == 1) res -= nums[i];
30+
else if (ops[i] == 2) res *= nums[i];
31+
else res /= nums[i];
32+
}
33+
mx = max(mx, res);
34+
mn = min(mn, res);
35+
} while (next_permutation(ops + 1, ops + n));
36+
cout << mx << '\n' << mn;
37+
}

0 commit comments

Comments
 (0)