tuki2501

BRICK.cpp

Nov 2nd, 2021 (edited)
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define task "BRICK"
  5.  
  6. int value(char c) {
  7.   if (c == '.') return 0;
  8.   return c - '0';
  9. }
  10.  
  11. int value(string s) {
  12.   return value(s[0]) + value(s[1]) + value(s[2]);
  13. }
  14.  
  15. int type(string s) {
  16.   int ret = 0;
  17.   ret += (s[2] != '.') << 0;
  18.   ret += (s[1] != '.') << 1;
  19.   ret += (s[0] != '.') << 2;
  20.   return ret;
  21. }
  22.  
  23. bool chmax(int &a, int b) {
  24.   if (a < b) {
  25.     a = b;
  26.     return true;
  27.   }
  28.   return false;
  29. }
  30.  
  31. signed main() {
  32.   cin.tie(0)->sync_with_stdio(0);
  33.   freopen(task".INP", "r", stdin );
  34.   freopen(task".OUT", "w", stdout);
  35.   int n; cin >> n;
  36.   vector<vector<pair<string,int>>> vec(8);
  37.   int ANS = 0;
  38.   for (int i = 1; i <= n; i++) {
  39.     string s; cin >> s;
  40.     vec[type(s)].push_back({s, i});
  41.     int t = 0;
  42.     for (int i = 0; i < 2; i++) {
  43.       if (s[i] == '.') t = 0;
  44.       else t += value(s[i]);
  45.       chmax(ANS, t);
  46.     }
  47.   }
  48.   for (int i = 0; i < 8; i++) {
  49.     sort(vec[i].begin(), vec[i].end());
  50.     reverse(vec[i].begin(), vec[i].end());
  51.   }
  52.   int MaxL = 0, MaxR = 0, SumM = 0;
  53.   if (vec[1].size()) chmax(MaxL, value(vec[1][0].first));
  54.   if (vec[3].size()) chmax(MaxL, value(vec[3][0].first));
  55.   if (vec[4].size()) chmax(MaxR, value(vec[4][0].first));
  56.   if (vec[6].size()) chmax(MaxR, value(vec[6][0].first));
  57.   for (auto &i : vec[7]) {
  58.     SumM += value(i.first);
  59.   }
  60.   vector<pair<int,int>> L = {{MaxL, 0}}, R = {{MaxR, -1}};
  61.   sort(vec[5].begin(), vec[5].end(),
  62.     [](pair<string,int> a, pair<string,int> b) {
  63.       return a.first[2] > b.first[2];
  64.   });
  65.   for (int i = 0; i < min(2, (int) vec[5].size()); i++) {
  66.     L.push_back({value(vec[5][i].first[2]), vec[5][i].second});
  67.   }
  68.   sort(vec[5].begin(), vec[5].end(),
  69.     [](pair<string,int> a, pair<string,int> b) {
  70.       return a.first[0] > b.first[0];
  71.   });
  72.   for (int i = 0; i < min(2, (int) vec[5].size()); i++) {
  73.     R.push_back({value(vec[5][i].first[0]), vec[5][i].second});
  74.   }
  75.   for (auto &i : L) for (auto &j : R) {
  76.     if (i.second == j.second) continue;
  77.     ANS = max(ANS, i.first + SumM + j.first);
  78.   }
  79.   cout << ANS << '\n';
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment