Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define task "BRICK"
- int value(char c) {
- if (c == '.') return 0;
- return c - '0';
- }
- int value(string s) {
- return value(s[0]) + value(s[1]) + value(s[2]);
- }
- int type(string s) {
- int ret = 0;
- ret += (s[2] != '.') << 0;
- ret += (s[1] != '.') << 1;
- ret += (s[0] != '.') << 2;
- return ret;
- }
- bool chmax(int &a, int b) {
- if (a < b) {
- a = b;
- return true;
- }
- return false;
- }
- signed main() {
- cin.tie(0)->sync_with_stdio(0);
- freopen(task".INP", "r", stdin );
- freopen(task".OUT", "w", stdout);
- int n; cin >> n;
- vector<vector<pair<string,int>>> vec(8);
- int ANS = 0;
- for (int i = 1; i <= n; i++) {
- string s; cin >> s;
- vec[type(s)].push_back({s, i});
- int t = 0;
- for (int i = 0; i < 2; i++) {
- if (s[i] == '.') t = 0;
- else t += value(s[i]);
- chmax(ANS, t);
- }
- }
- for (int i = 0; i < 8; i++) {
- sort(vec[i].begin(), vec[i].end());
- reverse(vec[i].begin(), vec[i].end());
- }
- int MaxL = 0, MaxR = 0, SumM = 0;
- if (vec[1].size()) chmax(MaxL, value(vec[1][0].first));
- if (vec[3].size()) chmax(MaxL, value(vec[3][0].first));
- if (vec[4].size()) chmax(MaxR, value(vec[4][0].first));
- if (vec[6].size()) chmax(MaxR, value(vec[6][0].first));
- for (auto &i : vec[7]) {
- SumM += value(i.first);
- }
- vector<pair<int,int>> L = {{MaxL, 0}}, R = {{MaxR, -1}};
- sort(vec[5].begin(), vec[5].end(),
- [](pair<string,int> a, pair<string,int> b) {
- return a.first[2] > b.first[2];
- });
- for (int i = 0; i < min(2, (int) vec[5].size()); i++) {
- L.push_back({value(vec[5][i].first[2]), vec[5][i].second});
- }
- sort(vec[5].begin(), vec[5].end(),
- [](pair<string,int> a, pair<string,int> b) {
- return a.first[0] > b.first[0];
- });
- for (int i = 0; i < min(2, (int) vec[5].size()); i++) {
- R.push_back({value(vec[5][i].first[0]), vec[5][i].second});
- }
- for (auto &i : L) for (auto &j : R) {
- if (i.second == j.second) continue;
- ANS = max(ANS, i.first + SumM + j.first);
- }
- cout << ANS << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment