Advertisement
Guest User

cak.cpp

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define rep(i, n) for (int i = 1; i <= n; ++i)
  3. using namespace std;
  4.  
  5. const int N = 205;
  6.  
  7. int n;
  8. long long a[N][N], b[N];
  9. long long f[N][N];
  10. long long res = 0;
  11. vector<pair<int,int> > vec;
  12.  
  13. void calc(int i,int r) {
  14.     vec.push_back({i, r});
  15.     if (r) {
  16.         rep(j, n + n) b[j] = a[i][j];
  17.         reverse(b + 1, b + n + n + 1);
  18.         rep(j, n + n) a[i][j] = b[j];
  19.     }
  20.     else {
  21.         rep(j, n + n) b[j] = a[j][i];
  22.         reverse(b + 1, b + n + n + 1);
  23.         rep(j, n + n) a[j][i] = b[j];
  24.     }
  25. }
  26.  
  27. void solve(int i,int j) {
  28.     if (a[i][j] == f[i][j]) return;
  29.     else if (a[i][n + n + 1 - j] == f[i][j]) {
  30.         calc(n + n + 1 - j, 0);
  31.         calc(j, 0);
  32.         calc(n + n + 1 - i, 1);
  33.         calc(j, 0);
  34.     }
  35.     else if (a[n + n + 1 - i][j] == f[i][j]) {
  36.         calc(n + n + 1 - i, 1);
  37.         calc(i, 1);
  38.         calc(n + n + 1 - j, 0);
  39.         calc(i, 1);
  40.     }
  41.     else {
  42.         calc(i, 1);
  43.         calc(n + n + 1 - j, 0);
  44.         calc(i, 1);
  45.     }
  46. }
  47.  
  48. int main() {
  49.     freopen("tabgame.inp", "r", stdin);
  50.     freopen("tabgame.out", "w", stdout);
  51.     scanf("%d", &n);
  52.     rep(i, n + n) rep(j, n + n) scanf("%lld", &a[i][j]);
  53.     rep(i, n) rep(j, n) {
  54.         f[i][j] = a[i][j];
  55.         f[i][j] = max(f[i][j], a[i][n + n + 1 - j]);
  56.         f[i][j] = max(f[i][j], a[n + n + 1 - i][j]);
  57.         f[i][j] = max(f[i][j], a[n + n + 1 - i][n + n + 1 - j]);
  58.         res += f[i][j];
  59.     }
  60.     printf("%lld\n", res);
  61.     rep(i, n) rep(j, n) solve(i, j);
  62.     printf("%d\n", (int)vec.size());
  63.     for (auto x : vec) {
  64.         if (x.second) printf("R ");
  65.         else printf("C ");
  66.         printf("%d\n", x.first);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement