Skip to content

Commit 2557d17

Browse files
authored
[20260102] BOJ / G5 / 간판 만들기 / 권혁준
1 parent d1a806d commit 2557d17

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
using ll = long long;
5+
6+
const ll INF = 1e18;
7+
const string S = "UOSPC";
8+
9+
int N;
10+
string s;
11+
ll arr[300000]{};
12+
13+
int main() {
14+
cin.tie(0)->sync_with_stdio(0);
15+
16+
cin>>N>>s;
17+
for(int i=0;i<N;i++) cin>>arr[i];
18+
19+
vector<ll> res(5, INF);
20+
for(int i=0;i<N;i++) {
21+
for(int j=0;j<5;j++) if(s[i] == S[j]) {
22+
if(!j) res[j] = min(res[j], arr[i]);
23+
else res[j] = min(res[j], res[j-1] + arr[i]);
24+
}
25+
}
26+
cout<<(res[4] == INF ? -1 : res[4]);
27+
28+
}
29+
```

0 commit comments

Comments
 (0)