# | User | Rating |
---|---|---|
1 | jiangly | 3977 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3483 |
8 | hos.lyric | 3381 |
9 | gamegame | 3374 |
10 | heuristica | 3358 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 162 |
3 | Um_nik | 161 |
4 | atcoder_official | 159 |
5 | djm03178 | 157 |
5 | Dominater069 | 157 |
7 | adamant | 154 |
8 | luogu_official | 152 |
8 | awoo | 152 |
10 | TheScrasse | 148 |
Name |
---|
Consider that in a reqular bracket sequence the amount of '(' and ')' must be equal. Let x be the amount of '(' and y be the amount of ')'. In case that x>y, you will have to pay the cost of placing ')' x-y times. In the opposite case, vice versa. Then let z be the amount of '?' left over. Just add z/2 * (c1+c2) where c1 and c2 are the costs of '(' and ')'. Because half will be opened and half will be closed. All of this assumes that a regular bracket sequence is achievable, so before this you just have to check if it actually is. If it is achievable, which is trivial to check, the greedy works because of the reasoning above.