-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10.cpp
57 lines (50 loc) · 1 KB
/
day10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef vector<int> vi;
int main() {
cin.tie(0)->sync_with_stdio(0);
freopen("input/test10", "r", stdin);
string s;
vector<string> strs;
while(cin >> s) strs.pb(s);
map<char,int> mp;
mp[')'] = 3;
mp[']'] = 57;
mp['}'] = 1197;
mp['>'] = 25137;
map<char,int> sm;
sm['('] = 1;
sm['['] = 2;
sm['{'] = 3;
sm['<'] = 4;
int cost = 0;
vi scores;
for(auto s : strs){
string st;
bool con = false;
for(auto c : s){
if(c == '(' || c == '[' || c== '{' || c=='<') st.pb(c);
else if( (c==')' && st.back()=='(') ||
st.back()==c-2) st.pop_back();
else {
cost+=mp[c];
con = true;
break;
}
}
if(con) continue;
int score = 0;
for(int i=sz(st);i>=0;--i){
score *= 5;
score += sm[st[i]];
}
scores.pb(score);
}
sort(all(scores));
cout << cost << "\n" << scores[sz(scores)/2];
}