Advertisement
Korotkodul

швб_21-22_N6 > 50min

Oct 23rd, 2022 (edited)
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50.  
  51. bool way(pii a, pii b) {
  52.     return a.first == b.first || a.second == b.second || abs(a.first - b.first) == abs(a.second - b.second);
  53. }
  54. vector <int> clr, tocomp, compsz;
  55. vector <vector <int> > G;
  56. int n;
  57. void dfs(int v, int comp) {
  58.     tocomp[v] = comp;
  59.     clr[v] = 1;
  60.     for (int u: G[v]) {
  61.         if (clr[u] == 0) {
  62.             dfs(u, comp);
  63.         }
  64.     }
  65.     clr[v] = 2;
  66. }
  67.  
  68. bool sh = 0;
  69.  
  70.  
  71. int main() {
  72.     ios::sync_with_stdio(0);
  73.     cin.tie(0);
  74.     cout.tie(0);
  75.     cin >> n;
  76.     string q; cin >> q;
  77.     pii str = {q[1] - '0' - 1, q[0] - 'A'};
  78.     vector <pii> pwn(n);
  79.     for (int i = 0; i < n; ++i) {
  80.         string s; cin >> s;
  81.         pwn[i] = {s[1] - '0' - 1, s[0] - 'A'};
  82.     }
  83.     G.resize(n);
  84.     for (int i = 0; i < n; ++i) {
  85.         for (int j = 0; j < n && j != i; ++j) {
  86.             if (way(pwn[i], pwn[j])) {
  87.                 G[i].pb(j);
  88.                 G[j].pb(i);
  89.             }
  90.         }
  91.     }
  92.     if (sh) {
  93.         cout << "pwn\n";
  94.         cvp(pwn);
  95.         cout << "G\n";
  96.         cvv(G);
  97.     }
  98.  
  99.     int cnt = -1;
  100.     clr.assign(n, 0);
  101.     tocomp.assign(n, -1);
  102.     for (int i = 0; i < n; ++i) {
  103.         if (clr[i] == 0) {
  104.             cnt++;
  105.             dfs(i, cnt);
  106.         }
  107.     }
  108.     vector <int> compsz(cnt + 1);
  109.     for (int i = 0; i <= cnt; ++i) {
  110.         compsz[i] = count(tocomp.begin(), tocomp.end(), i);
  111.     }
  112.     int ans = 0, bst = -1;
  113.     for (int i = 0; i < n; ++i) {
  114.         if (compsz[ tocomp[i] ] > ans) {
  115.             bst = tocomp[i];
  116.             ans = compsz[ tocomp[i] ];
  117.         }
  118.     }
  119.     cout << ans << "\n";
  120.     if (sh) {
  121.         cout << "clr\n";
  122.         cv(clr);
  123.         cout << "tocomp\n";
  124.         cv(tocomp);
  125.         cout << "compsz\n";
  126.         cv(compsz);
  127.         cout << "bst = " << bst << "\n";
  128.     }
  129.     for (int i = 0; i < n; ++i) {
  130.         if (tocomp[i] == bst) {
  131.             if (sh) {
  132.                 cout << pwn[i].first << ' '<< pwn[i].second << "\n";
  133.             }
  134.             cout << char( 'A' + (pwn[i].second )) <<  (pwn[i].first + 1) << "\n";
  135.         }
  136.     }
  137. }
  138. /*
  139. 11 A1
  140. A8
  141. G7
  142. F5
  143. F4
  144. F3
  145. F2
  146. F1
  147. E3
  148. E2
  149. D3
  150. D2
  151. */
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement