Advertisement
K_Y_M_bl_C

Untitled

Nov 1st, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #ifdef _DEBUG
  2. #define _GLIBCXX_DEBUG
  3. #endif
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10. typedef pair<int, int> pii;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef long double ld;
  14.  
  15. #define mk make_pair
  16. #define inb push_back
  17. #define X first
  18. #define Y second
  19. #define all(v) v.begin(), v.end()
  20. #define sqr(x) ((x) * (x))
  21. #define TIME 1.0 * clock() / CLOCKS_PER_SEC
  22. #define y1 AYDARBOG
  23. //continue break pop_back return scanf
  24.  
  25. int solve();
  26.  
  27. int main()
  28. {
  29.     //ios_base::sync_with_stdio(0);
  30.     //cin.tie(0);
  31. #define TASK "chevaux"
  32. #ifndef _DEBUG
  33.     //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
  34. #endif
  35.     solve();
  36. #ifdef _DEBUG
  37.     fprintf(stderr, "\nTIME: %.3f\n", TIME);
  38. #endif
  39. }
  40.  
  41. const int BUFSZ = (int)4e5 + 7;
  42. char buf[BUFSZ];
  43. string get_str()
  44. {
  45.     scanf(" %s", buf);
  46.     return string(buf);
  47. }
  48.  
  49. const int INF = 1e9 + 7;
  50.  
  51. int solve()
  52. {
  53.     int n, m, k;
  54.     scanf("%d %d %d", &n, &m, &k);
  55.     char a[n][m + 1];
  56.     for (int i = 0; i < n; ++i)
  57.     {
  58.         scanf(" %s", a[i]);
  59.     }
  60.     vector<pii> swaps(m / 2, mk(0, 2));
  61.     int ans = 0;
  62.     pii solo = mk(0, 0);
  63.     if (m & 1)
  64.     {
  65.         solo = mk(0, 1);
  66.         for (int i = 0; i < n / 2; ++i)
  67.         {
  68.             if (a[i][m / 2] != a[n - i - 1][m / 2])
  69.             {
  70.                 ++solo.X;
  71.             }
  72.         }
  73.     }
  74.     for (int i = 0; i < n; ++i)
  75.     {
  76.         int ri = n - i - 1;
  77.         for (int j = 0; j < m / 2; ++j)
  78.         {
  79.             int rj = m - j - 1;
  80.             if (a[i][j] != a[i][rj])
  81.             {
  82.                 ++ans;
  83.                 //fprintf(stderr, "%d %d :: %c %c\n", i, j, a[i][j], a[i][rj]);
  84.             }
  85.             if (i < n / 2)
  86.             {
  87.                 char c1 = a[i][j];
  88.                 char c2 = a[i][rj];
  89.                 char c3 = a[ri][j];
  90.                 char c4 = a[ri][rj];
  91.                 //fprintf(stderr, "%c %c\n%c %c\n", c1, c2, c3, c4);
  92.                 //c1 c2
  93.                 //c3 c4
  94.                 //c1 == c2 c3 == c4
  95.                 if (c1 == c2 && c3 == c4)
  96.                 {
  97.                     if (c1 == c3)
  98.                         swaps[j].X += 0;
  99.                     else
  100.                         swaps[j].X += 2;
  101.                 }
  102.                 if (c1 == c2 && c3 != c4)
  103.                 {
  104.                     if (c3 != c1 && c3 != c2 && c4 != c1 && c4 != c2)
  105.                         swaps[j].X += 1;
  106.                 }
  107.                 if (c1 != c2 && c3 == c4)
  108.                 {
  109.                     if (c1 != c3 && c1 != c4 && c2 != c3 && c2 != c4)
  110.                         swaps[j].X += 1;
  111.                 }
  112.                 if (c1 != c2 && c3 != c4)
  113.                 {
  114.                     if (c1 != c3 && c1 != c4 && c2 != c3 && c2 != c4)
  115.                         swaps[j].X += 1;
  116.                 }
  117.                 //fprintf(stderr, "%d\n", swaps[j].X);
  118.             }
  119.         }
  120.     }
  121.     /*for (auto cur : swaps)
  122.     {
  123.         printf("%d %d\n", cur.X, cur.Y);
  124.     }//*/
  125.     //printf("ANS : %d %d\n", ans, solo.X);
  126.     sort(all(swaps), [&](pii x, pii y)
  127.     {
  128.         return x.X < y.X;
  129.     });
  130.     int cr = 0;
  131.     for (auto x : swaps)
  132.     {
  133.         if (cr >= k)
  134.             break;
  135.         if (solo.Y)
  136.         {
  137.             if (solo.Y + cr >= k && cr + x.Y >= k)
  138.             {
  139.                 ans += min(x.X, solo.X);
  140.                 printf("%d\n", ans);
  141.                 exit(0);
  142.             }
  143.         }
  144.         cr += x.Y;
  145.         ans += x.X;
  146.         if (cr >= k)
  147.             break;
  148.     }
  149.     if (solo.Y)
  150.     {
  151.         if (solo.Y + cr == k)
  152.         {
  153.             ans += solo.X;
  154.             printf("%d\n", ans);
  155.             exit(0);
  156.         }
  157.     }
  158.     printf("%d\n", ans);
  159.     return 0;
  160. }
  161. /*
  162. 4 5 5
  163. cdcde
  164. eeace
  165. ddcda
  166. bccbc
  167. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement