Advertisement
SorahISA

2019 NHSPC north1 pA

Nov 12th, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  5. #define X first
  6. #define Y second
  7. #define Push push_back
  8. #define ALL(x) x.begin(), x.end()
  9.  
  10. using lli = long long;
  11. using pll = pair<lli, lli>;
  12. using Double = long double;
  13. template<typename T>
  14. using Vector = vector<vector<T>>;
  15. template<typename T>
  16. using prior = priority_queue<T>;
  17.  
  18. bool cmp(pair<string, int> a, pair<string, int> b) {
  19.     if (a.Y == b.Y) return a.X < b.X;
  20.     return a.Y > b.Y;
  21. }
  22.  
  23. int main() {
  24.     IOS;
  25.     int n, m, p;
  26.     cin >> n >> m;
  27.    
  28.     vector<pair<string, int>> vs(n, {"", 0});
  29.     for (auto &x : vs) cin >> x.X;
  30.    
  31.     cin >> p;
  32.     string vote;
  33.    
  34.     while (p--) {
  35.         cin >> vote;
  36.         if (vote.size() != n) continue;
  37.        
  38.         bool flag = false;
  39.         int cnt = 0;
  40.        
  41.         for (auto x : vote) {
  42.             if (x == '0'); // good
  43.             else if (x == '*') {
  44.                 if (++cnt > m) break;
  45.             }
  46.             else {
  47.                 flag = true;
  48.                 break;
  49.             }
  50.         }
  51.        
  52.         if (flag or cnt > m) continue;
  53.        
  54.         for (int i = 0; i < n; ++i) {
  55.             vs[i].Y += (vote[i] == '*');
  56.         }
  57.     }
  58.    
  59.     sort(ALL(vs), cmp);
  60.    
  61.     for (auto x : vs) cout << x.X << ' ' << x.Y << "\n";
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement