Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define rep(i, n) for (int i = 1; i <= n; ++i)
- using namespace std;
- const int N = 205;
- int n;
- long long a[N][N], b[N];
- long long f[N][N];
- long long res = 0;
- vector<pair<int,int> > vec;
- void calc(int i,int r) {
- vec.push_back({i, r});
- if (r) {
- rep(j, n + n) b[j] = a[i][j];
- reverse(b + 1, b + n + n + 1);
- rep(j, n + n) a[i][j] = b[j];
- }
- else {
- rep(j, n + n) b[j] = a[j][i];
- reverse(b + 1, b + n + n + 1);
- rep(j, n + n) a[j][i] = b[j];
- }
- }
- void solve(int i,int j) {
- if (a[i][j] == f[i][j]) return;
- else if (a[i][n + n + 1 - j] == f[i][j]) {
- calc(n + n + 1 - j, 0);
- calc(j, 0);
- calc(n + n + 1 - i, 1);
- calc(j, 0);
- }
- else if (a[n + n + 1 - i][j] == f[i][j]) {
- calc(n + n + 1 - i, 1);
- calc(i, 1);
- calc(n + n + 1 - j, 0);
- calc(i, 1);
- }
- else {
- calc(i, 1);
- calc(n + n + 1 - j, 0);
- calc(i, 1);
- }
- }
- int main() {
- freopen("tabgame.inp", "r", stdin);
- freopen("tabgame.out", "w", stdout);
- scanf("%d", &n);
- rep(i, n + n) rep(j, n + n) scanf("%lld", &a[i][j]);
- rep(i, n) rep(j, n) {
- f[i][j] = a[i][j];
- f[i][j] = max(f[i][j], a[i][n + n + 1 - j]);
- f[i][j] = max(f[i][j], a[n + n + 1 - i][j]);
- f[i][j] = max(f[i][j], a[n + n + 1 - i][n + n + 1 - j]);
- res += f[i][j];
- }
- printf("%lld\n", res);
- rep(i, n) rep(j, n) solve(i, j);
- printf("%d\n", (int)vec.size());
- for (auto x : vec) {
- if (x.second) printf("R ");
- else printf("C ");
- printf("%d\n", x.first);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement