Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _DEBUG
- #define _GLIBCXX_DEBUG
- #endif
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef long double ld;
- #define mk make_pair
- #define inb push_back
- #define X first
- #define Y second
- #define all(v) v.begin(), v.end()
- #define sqr(x) ((x) * (x))
- #define TIME 1.0 * clock() / CLOCKS_PER_SEC
- #define y1 AYDARBOG
- //continue break pop_back return scanf
- int solve();
- int main()
- {
- //ios_base::sync_with_stdio(0);
- //cin.tie(0);
- #define TASK "chevaux"
- #ifndef _DEBUG
- //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
- #endif
- solve();
- #ifdef _DEBUG
- fprintf(stderr, "\nTIME: %.3f\n", TIME);
- #endif
- }
- const int BUFSZ = (int)4e5 + 7;
- char buf[BUFSZ];
- string get_str()
- {
- scanf(" %s", buf);
- return string(buf);
- }
- const int INF = 1e9 + 7;
- int solve()
- {
- int n, m, k;
- scanf("%d %d %d", &n, &m, &k);
- char a[n][m + 1];
- for (int i = 0; i < n; ++i)
- {
- scanf(" %s", a[i]);
- }
- vector<pii> swaps(m / 2, mk(0, 2));
- int ans = 0;
- pii solo = mk(0, 0);
- if (m & 1)
- {
- solo = mk(0, 1);
- for (int i = 0; i < n / 2; ++i)
- {
- if (a[i][m / 2] != a[n - i - 1][m / 2])
- {
- ++solo.X;
- }
- }
- }
- for (int i = 0; i < n; ++i)
- {
- int ri = n - i - 1;
- for (int j = 0; j < m / 2; ++j)
- {
- int rj = m - j - 1;
- if (a[i][j] != a[i][rj])
- {
- ++ans;
- //fprintf(stderr, "%d %d :: %c %c\n", i, j, a[i][j], a[i][rj]);
- }
- if (i < n / 2)
- {
- char c1 = a[i][j];
- char c2 = a[i][rj];
- char c3 = a[ri][j];
- char c4 = a[ri][rj];
- //fprintf(stderr, "%c %c\n%c %c\n", c1, c2, c3, c4);
- //c1 c2
- //c3 c4
- //c1 == c2 c3 == c4
- if (c1 == c2 && c3 == c4)
- {
- if (c1 == c3)
- swaps[j].X += 0;
- else
- swaps[j].X += 2;
- }
- if (c1 == c2 && c3 != c4)
- {
- if (c3 != c1 && c3 != c2 && c4 != c1 && c4 != c2)
- swaps[j].X += 1;
- }
- if (c1 != c2 && c3 == c4)
- {
- if (c1 != c3 && c1 != c4 && c2 != c3 && c2 != c4)
- swaps[j].X += 1;
- }
- if (c1 != c2 && c3 != c4)
- {
- if (c1 != c3 && c1 != c4 && c2 != c3 && c2 != c4)
- swaps[j].X += 1;
- }
- //fprintf(stderr, "%d\n", swaps[j].X);
- }
- }
- }
- /*for (auto cur : swaps)
- {
- printf("%d %d\n", cur.X, cur.Y);
- }//*/
- //printf("ANS : %d %d\n", ans, solo.X);
- sort(all(swaps), [&](pii x, pii y)
- {
- return x.X < y.X;
- });
- int cr = 0;
- for (auto x : swaps)
- {
- if (cr >= k)
- break;
- if (solo.Y)
- {
- if (solo.Y + cr >= k && cr + x.Y >= k)
- {
- ans += min(x.X, solo.X);
- printf("%d\n", ans);
- exit(0);
- }
- }
- cr += x.Y;
- ans += x.X;
- if (cr >= k)
- break;
- }
- if (solo.Y)
- {
- if (solo.Y + cr == k)
- {
- ans += solo.X;
- printf("%d\n", ans);
- exit(0);
- }
- }
- printf("%d\n", ans);
- return 0;
- }
- /*
- 4 5 5
- cdcde
- eeace
- ddcda
- bccbc
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement