File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments