Problem:
ポスター (Poster)
問題文
JOI 君は文化祭でのクラスの出し物を宣伝するため，ポスターを作った．そのポスターは
N
行
N
列のマス目の形をしており，各マスは赤，緑，青のいずれかの色で塗られている．ポスターの上から
i
行目，左から
j
列目 (
1 ≦ i ≦ N
，
1 ≦ j ≦ N
) にあるマスの色は，
S
i,j
=
`R' のとき赤色，
S
i,j
=
`G' のとき緑色，
S
i,j
=
`B' のとき青色である．
しかし，このポスターにクラスのみんなは満足してはくれなかった．話し合いの結果，マス目の形は変えずに色の配置を変えることで，新しいポスターを作ることに決まった．新しいポスターの上から
i
行目，左から
j
列目 (
1 ≦ i ≦ N
，
1 ≦ j ≦ N
) にあるマスの色は，
T
i,j
=
`R' のとき赤色，
T
i,j
=
`G' のとき緑色，
i,j
=
`B' のとき青色となるようにする．
JOI 君は今あるポスターに以下のいずれかの作業を繰り返し行うことで，新しいポスターを作ることにした．
マスを一つ選び，そのマスの色を好きな色に塗りなおす．
ポスター全体を
90°
時計回りに回転させる．このとき，もともと上から
i
行目，左から
j
列目 (
1 ≦ i ≦ N
，
1 ≦ j ≦ N
) にあるマスは，上から
j
行目，左から
N-i+1
列目にあるマスに移動する．
ポスター全体を
90°
反時計回りに回転させる．このとき，もともと上から
i
行目，左から
j
列目 (
1 ≦ i ≦ N
，
1 ≦ j ≦ N
) にあるマスは，上から
N-j+1
行目，左から
i
列目にあるマスに移動する．
JOI 君はどの作業をするにも
1
分かかる．JOI 君が作ったポスター，新しく作るポスターの情報が与えられたとき，JOI 君が新しいポスターを作るのに最短で何分かかるかを求めるプログラムを作成せよ．
制約
1 ≦ N ≦ 500
．
S
i,j
は `R'，`G'，`B' のいずれかである．
T
i,j
は `R'，`G'，`B' のいずれかである．
入力
入力は以下の形式で標準入力から与えられる．
N
S
1,1
… S
1,N
:
S
N,1
… S
N,N
T
1,1
… T
1,N
:
T
N,1
… T
N,N
出力
新しいポスターを作るのに最短で何分かかるかを
1
行で出力せよ．
入出力例
入力例 1
3
RRR
GGG
BBB
RRR
RRR
RRR
出力例 1
6
2
行目と
3
行目にあるマス目をすべて赤色に塗りかえればよい．これには
6
分かかる．
入力例 2
3
RRR
GGG
BBB
RGB
RGB
RGB
出力例 2
1
ポスター全体を
90°
反時計回りに回転させればよい．これには
1
分かかる．
入力例 3
6
RRRBBB
RRRBBB
RRRBBB
GGGRRG
GGGRRG
GGGBBR
RRRGGG
RRRGGG
RRRGGG
BBBRRB
BBBRRB
BBBGGR
出力例 3
10
情報オリンピック日本委員会
作 『第 19 回日本情報オリンピック JOI 2019/2020 一次予選競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include<string>
#include <climits>
using namespace std;


int main() {
    int N;
    int ans = INT_MAX;
    cin >> N;
    vector<vector<char>>li0(N, vector<char>(N));
    vector<vector<char>>li90(N, vector<char>(N));
    vector<vector<char>>li180(N, vector<char>(N));
    vector<vector<char>>li270(N, vector<char>(N));
    
    vector<vector<char>>A(N, vector<char>(N));
    //li0set
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> li0[i][j];
        }
    }
    
    //Aset
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    if (N == 1) {
        if (li0[0][0] != A[0][0]) {
            ans = 1;
        }
        else {
            ans=0;
        }
    }
    else {
        //li90set
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                li90[N - j - 1][i] = li0[i][j];
            }
        }

        //li270set
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                li270[j][N - i - 1] = li0[i][j];
            }
        }

        //li180set
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                li180[N - i - 1][N - j - 1] = li0[i][j];
            }
        }


        int ka = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (li0[i][j] != A[i][j]) {
                    ka += 1;
                }
            }
        }
        ans = min(ka, ans);
        ka = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (li90[i][j] != A[i][j]) {
                    ka += 1;
                }
            }
        }
        ka += 1;
        ans = min(ka, ans);
        ka = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (li270[i][j] != A[i][j]) {
                    ka += 1;
                }
            }
        }
        ka += 1;
        ans = min(ka, ans);
        ka = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (li180[i][j] != A[i][j]) {
                    ka += 1;
                }
            }
        }
        ka += 2;
        ans = min(ka, ans);
    }
    cout << ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4680
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include<string>
using namespace std;


int main() {
    int N;
    int ans = 1000;
    cin >> N;
    vector<vector<char>>li0(N, vector<char>(N));
    vector<vector<char>>li90(N, vector<char>(N));
    vector<vector<char>>li180(N, vector<char>(N));
    vector<vector<char>>li270(N, vector<char>(N));
    
    vector<vector<char>>A(N, vector<char>(N));
    //li0set
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> li0[i][j];
        }
    }
    
    //Aset
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    
    //li90set
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            li90[N - j - 1][i] = li0[i][j];
        }
    }
    
    //li270set
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            li270[j][N-i-1] = li0[i][j];
        }
    }
    
    //li180set
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            li180[j][N - i - 1] = li270[i][j];
        }
    }
    
    int ka = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (li0[i][j] != A[i][j]) {
                ka += 1;
            }
        }
    }
    ans = min(ka, ans);
    ka = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (li90[i][j] != A[i][j]) {
                ka += 1;
            }
        }
    }
    ans = min(ka, ans);
    ka = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (li270[i][j] != A[i][j]) {
                ka += 1;
            }
        }
    }
    ans = min(ka, ans);
    ka = 2;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (li180[i][j] != A[i][j]) {
                ka += 1;
            }
        }
    }
    ans = min(ka, ans);

    cout << ans<<endl;
}
accuracy: 0.15
time_ms: 10
memory_kb: 4656
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

vector<vector<char>> f(const int n,const vector<vector<char>>& s){
    vector<vector<char>> res(n,vector<char>(n));
    rep(i,n){
        rep(j,n){
            res[n-j-1][i]=s[i][j];
        }
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<vector<char>> s(n,vector<char>(n)),t(n,vector<char>(n));
    rep(i,n){
        rep(j,n){
            cin >> s[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            cin >> t[i][j];
        }
    }

    //回転0回
    int res0=0;
    rep(i,n){
        rep(j,n){
            if(s[i][j]!=t[i][j]){
                res0++;
            }
        }
    }

    //1回
    int res1=1;
    s=f(n,s);
    rep(i,n){
        rep(j,n){
            if(s[i][j]!=t[i][j]){
                res1++;
            }
        }
    }
    int res2=2;
    s=f(n,s);
    rep(i,n){
        rep(j,n){
            if(s[i][j]!=t[i][j]){
                res2++;
            }
        }
    }    
    int res3=1;
    s=f(n,s);
    rep(i,n){
        rep(j,n){
            if(s[i][j]!=t[i][j]){
                res3++;
            }
        }
    }
    cout << min({res0,res1,res2,res3}) << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4092
final_rank: 5

code_snippet: #include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 500 + 10;
char a[N][N], b[N][N], c[N][N], d[N][N], s[N][N], t[N][N];
int main()
{
    ll n;
    cin>>n;
    for(int i = 1; i<= n ; i++)
    {
        for(int j = 1 ; j<= n ; j++)
        {
            cin>>s[i][j];
        }
    }
    for(int i = 1 ; i<= n ; i++)
    {
        for(int j = 1 ; j<= n ; j++)
        {
            cin>>t[i][j];
        }
    }
    for(int i = 1 ; i<= n ; i++)
    {
        for(int j = 1; j<= n ; j++)
        {
            a[i][j] = s[j][n - i + 1];
            b[i][j] = s[n - j + 1][i];
        }
    }
    for(int i = 1 ; i<= n ; i++)
    {
        for(int j = 1; j<= n ; j++)
        {
            c[i][j] = a[j][n - i + 1];
        }
    }
    ll d1 = 0 , d2 = 1 , d3 = 1 , d4 = 2;
    for(int i = 1; i<= n ; i++)
    {
        for(int j = 1 ; j<= n ; j++)
        {
            if(s[i][j] != t[i][j]) d1 ++;
            if(a[i][j] != t[i][j]) d2 ++;
            if(b[i][j] != t[i][j]) d3 ++;
            if(c[i][j] != t[i][j]) d4 ++;
        }
    }
    cout<<min({d1 , d2 , d3 , d4})<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4668
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
using namespace std;

void rotateClockwise(vector<vector<char>>& poster) {
    int N = poster.size();
    vector<vector<char>> rotated(N, vector<char>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            rotated[j][N-i-1] = poster[i][j];
        }
    }
    poster = rotated;
}

int countDifferences(vector<vector<char>>& S, vector<vector<char>>& T) {
    int count = 0;
    int N = S.size();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (S[i][j] != T[i][j]) count++;
        }
    }
    return count;
}

int main() {
    int N;
    cin >> N;

    vector<vector<char>> S(N, vector<char>(N));
    vector<vector<char>> T(N, vector<char>(N));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> S[i][j];
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> T[i][j];
        }
    }

    int minCount = countDifferences(S, T);
    
    rotateClockwise(S);
    minCount = min(minCount, countDifferences(S, T) + 1);

    rotateClockwise(S);
    minCount = min(minCount, countDifferences(S, T) + 2);

    rotateClockwise(S);
    minCount = min(minCount, countDifferences(S, T) + 1);

    cout << minCount << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4024
final_rank: 3

code_snippet: #include<iostream>
using namespace std;

char s[500][500];
char t[500][500];
char keep[500][500];

int paint(int n, int cnt)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                cnt++;
        }
    }
    return cnt;
}

int rotate(int n, int k, int cnt, char drc)
{
    if (drc == 'r')
    {
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
            cnt++;
        }
        cnt = paint(n, cnt);
    }
    else if (drc == 'l')
    {
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
            cnt++;
        }
        cnt = paint(n, cnt);
    }
    return cnt;
}

int compare(int cnt, int min)
{
    if (min > cnt)
        min = cnt;
    return min;
}

int main()
{
    int n, counter = 0, min = 250001;
    cin >> n;
    char org[n][n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }
    counter = paint(n, counter);
    min = compare(counter, min);
    counter = 0;
    for (int k = 1; k <= 3; k++)
    {
        counter = rotate(n, k, counter, 'r');
        min = compare(counter, min);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
        counter = 0;
    }
    counter = 0;
    for (int k = 1; k <= 3; k++)
    {
        counter = rotate(n, k, counter, 'l');
        min = compare(counter, min);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
        counter = 0;
    }
    cout << min << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4052
final_rank: 4

code_snippet: #include<iostream>
using namespace std;

int main()
{
    long n, counter = 0, min = 250001;
    cin >> n;
    char s[n][n], t[n][n], keep[n][n], org[n][n];
    for (long i = 0; i < n; i++)
        cin >> s[i];
    for (long i = 0; i < n; i++)
        cin >> t[i];
    for (long i = 0; i < n; i++)
    {
        for (long j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }

    for (long i = 0; i < n; i++)
    {
        for (long j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                counter++;
        }
    }
    if (min > counter)
        min = counter;
    counter = 0;

    for (int k = 1; k <= 4; k++)
    {
        //時計回り
        for (int l = 1; l <= k; l++)
        {
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            counter++;
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }

    for (long i = 0; i < n; i++)
    {
        for (long j = 0; j < n; j++)
            keep[i][j] = org[i][j];
    }

    for (int k = 1; k <= 4; k++)
    {
        //反時計回り
        for (int l = 1; l <= k; l++)
        {
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            counter++;
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }
    cout << min << endl;
    return 0;
}
accuracy: 0.15
time_ms: 20
memory_kb: 3960
final_rank: 17

code_snippet: #include<iostream>
using namespace std;

int main()
{
    long n, counter = 0, min = 250001;
    cin >> n;
    char s[n][n], t[n][n], keep[n][n], org[n][n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }

    for (long i = 0; i < n; i++)
    {
        for (long j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                counter++;
        }
    }
    if (min > counter)
        min = counter;
    counter = 0;

    for (int k = 1; k <= 4; k++)
    {
        //時計回り
        for (int l = 1; l <= k; l++)
        {
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            counter++;
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }

    for (long i = 0; i < n; i++)
    {
        for (long j = 0; j < n; j++)
            keep[i][j] = org[i][j];
    }

    for (int k = 1; k <= 4; k++)
    {
        //反時計回り
        for (int l = 1; l <= k; l++)
        {
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            counter++;
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (long i = 0; i < n; i++)
        {
            for (long j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }
    cout << min << endl;
    return 0;
}
accuracy: 0.15
time_ms: 10
memory_kb: 4068
final_rank: 15

code_snippet: #include<iostream>
using namespace std;

int main()
{
    long n, counter = 0, min = 500 * 500 + 1;
    cin >> n;
    char s[n][n], t[n][n], keep[n][n], org[n][n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                counter++;
        }
    }
    if (min > counter)
        min = counter;
    counter = 0;

    for (int k = 1; k <= 4; k++)
    {
        //時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            keep[i][j] = org[i][j];
    }

    for (int k = 1; k <= 4; k++)
    {
        //反時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }
    cout << min << endl;
    return 0;
}
accuracy: 0.15
time_ms: 20
memory_kb: 3976
final_rank: 18

code_snippet: #include<iostream>
using namespace std;

int main()
{
    int n, counter = 0, min = 500 * 500 + 1;
    cin >> n;
    char s[n][n], t[n][n], keep[n][n], org[n][n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                counter++;
        }
    }
    if (min > counter)
        min = counter;
    counter = 0;

    for (int k = 1; k <= 4; k++)
    {
        //時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            keep[i][j] = org[i][j];
    }

    for (int k = 1; k <= 4; k++)
    {
        //反時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }
    cout << min << endl;
    return 0;
}
accuracy: 0.15
time_ms: 20
memory_kb: 4044
final_rank: 20

code_snippet: #include<iostream>
using namespace std;

int main()
{
    int n, counter = 0, min = 501;
    cin >> n;
    char s[n][n], t[n][n], keep[n][n], org[n][n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            keep[i][j] = s[i][j];
            org[i][j] = s[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (s[i][j] != t[i][j])
                counter++;
        }
    }
    if (min > counter)
        min = counter;
    counter = 0;

    for (int k = 1; k <= 4; k++)
    {
        //時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[j][n - i - 1] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            keep[i][j] = org[i][j];
    }

    for (int k = 1; k <= 4; k++)
    {
        //反時計回り
        for (int l = 1; l <= k; l++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    s[n - j - 1][i] = keep[i][j];
            }
            counter++;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                    keep[i][j] = s[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (s[i][j] != t[i][j])
                    counter++;
            }
        }
        if (min > counter)
            min = counter;
        counter = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                keep[i][j] = org[i][j];
        }
    }
    cout << min << endl;
    return 0;
}
accuracy: 0.15
time_ms: 20
memory_kb: 3980
final_rank: 19

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int n,wa;
	cin >> n;
	string mon[500] = {};
	string to[500] = {};
	string ans[500] = {};
	int jud[4] = {0,1,1,2};

	for (int i = 0; i < n; i++) {
		cin >> mon[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> ans[i];
	}

	for (int i = 0; i < 500; i++) {
		for (int j = 0; j < 500; j++) {
			to[i]+='a';
		}
	}
	
	for (int ro = 0; ro < 4; ro++) {
		
		if (ro == 0) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					to[i][j] = mon[i][j];
				}
			}
		}

		

		
		if (ro == 1) { //右
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					to[i][j] = mon[n-j-1][i];
				}
			}
		}

		if (ro == 2) { //左
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					to[i][j] = mon[j][n-i-1];
				}
			}
		}

		if (ro == 3) { //反転
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					to[i][j] = mon[n - i - 1][n - j - 1];
				}
			}
		}


		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (to[i][j] != ans[i][j]) {
					jud[ro]++;
				}
			}
		}
		
	}
	wa = jud[0];
	wa = min(wa, jud[1]);
	wa = min(wa, jud[2]);
	wa = min(wa, jud[3]);
	cout << wa<<endl;

}
accuracy: 1
time_ms: 10
memory_kb: 3896
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>
#include <random>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;
const ll inf = 1e9;
const ll INF = 1e17;

void pline(vector<ll> lis){
    rep(i,0,lis.size()){
        printf ("%lld",lis[i]);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

void pline(vector<pair<ll,ll>> lis){
    rep(i,0,lis.size()){
        printf ("/%lld,%lld/",lis[i].first,lis[i].second);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

/*
void pmap(map<ll,mint>& lis){
    for (auto p : lis){
        printf ("%lld:%lld ,",p.first,p.second.val());
    }
    printf ("\n");
}*/

void RotR(vector<string>& S){

    ll N = S.size();
    vector<string> R;
    rep(i,0,S.size()) R.push_back(S[i]);

    rep(i,0,S.size()){
        rep(j,0,S.size()){
            R[j][N-1-i] = S[i][j];
        }
    }

    rep(i,0,S.size()){
        rep(j,0,S.size()){
            S[i][j] = R[i][j];
        }
    }
}

int main(){

    //ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);

    ll N;
    cin >> N;

    vector<string> S(N);
    vector<string> T(N);

    rep(i,0,N) cin >> S[i];
    rep(i,0,N) cin >> T[i];

    vector<ll> plus = {0,1,2,1};

    ll ans = N*N;
    rep(i,0,4){

        ll now = 0;
        rep(x,0,N){
            rep(y,0,N){
                if (S[x][y] != T[x][y]) now++;
            }
        }

        now += plus[i];
        ans = min(ans, now);

        RotR(S);

        //rep(xx,0,N) cout << S[xx] << endl;
        //cout << now << endl;
    }

    cout << ans << endl;
}

/*

区間だよなぁ
dp[i] = フリー区間の最左がiの時の最大値

*/
accuracy: 1
time_ms: 10
memory_kb: 4632
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n, ans = 0, cnt = 0;
  char lf;
  cin >> n;
  vector<vector<char> > s(n, vector<char>(n)), t(n, vector<char>(n)), tmp(n, vector<char>(n));

  for (int i = 0; i < n; i++) {
    scanf("%c", &lf);
    for (int j = 0; j < n; j++) scanf("%c", &s.at(i).at(j));
  }
  for (int i = 0; i < n; i++) {
    scanf("%c", &lf);
    for (int j = 0; j < n; j++) scanf("%c", &t.at(i).at(j));
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s.at(i).at(j) != t.at(i).at(j)) cnt++;
    }
  }
  ans = cnt;
  cnt = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s.at(i).at(j) != t.at(j).at(n-i-1)) cnt++;
    }
  }
  ans = min(ans, cnt + 1);
  cnt = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s.at(i).at(j) != t.at(n-j-1).at(i)) cnt++;
      tmp.at(i).at(j) = s.at(n-j-1).at(i);
    }
  }
  ans = min(ans, cnt + 1);
  cnt = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (tmp.at(i).at(j) != t.at(j).at(n-i-1)) cnt++;
    }
  }
  ans = min(ans, cnt + 2);

  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3760
final_rank: 1

code_snippet: #include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
string r = "";
string s = "";
string t = "";
for (int i = 0; i < n; i++){cin>>r;s += r;}
for (int i = 0; i < n; i++){cin>>r;t += r;}
char l1[n*n];
char l2[n*n];
char r1[n*n];
int a;int b;
for (int k = 0; k < n*n; k++){
a=k/n;b=k%n;
l1[n*(n-1-b)+a]=s[k];
l2[n*(n-1-a)+(n-1-b)]=s[k];
r1[n*b+(n-1-a)]=s[k];
}
int cnt[]={0,1,2,1};
for (int i = 0; i < n*n; i++){
if(s[i]!=t[i]){cnt[0]++;}
if(l1[i]!=t[i]){cnt[1]++;}
if(l2[i]!=t[i]){cnt[2]++;}
if(r1[i]!=t[i]){cnt[3]++;}
}
int min=0;
min = cnt[0]<cnt[1] ? cnt[0]:cnt[1];
min = min<cnt[2] ? min:cnt[2];
min = min<cnt[3] ? min:cnt[3];
cout<<min<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4364
final_rank: 9

code_snippet: #include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
string r = "";
string s = "";
string t = "";
for (int i = 0; i < n; i++){cin>>r;s += r;}
for (int i = 0; i < n; i++){cin>>r;t += r;}
char l1[n*n];
char l2[n*n];
char r1[n*n];
int a;int b;
for (int k = 0; k < n*n; k++){
    a=k/n;b=k%n;
    l1[n*(n-1-b)+a]=s[k];
    l2[n*(n-1-a)+(n-1-b)]=s[k];
    r1[n*b+(n-1-a)]=s[k];
}
int cnt[]={0,1,2,1};
for (int i = 0; i < n*n; i++){
    if(s[i]!=t[i]){cnt[0]++;}
    if(l1[i]!=t[i]){cnt[1]++;}
    if(l2[i]!=t[i]){cnt[2]++;}
    if(r1[i]!=t[i]){cnt[3]++;}
}
int min=0;
min = cnt[0]<cnt[1] ? cnt[0]:cnt[1];
min = min<cnt[2] ? min:cnt[2];
min = min<cnt[3] ? min:cnt[3];
cout<<min<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4336
final_rank: 7

code_snippet: #include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
string r = "";
string s = "";
string t = "";
for (int i = 0; i < n; i++){cin>>r;s += r;}
for (int i = 0; i < n; i++){cin>>r;t += r;}
char l1[n*n];
char l2[n*n];
char r1[n*n];
int a;int b;
for (int k = 0; k < n*n; k++){
    a=k/n;b=k%n;
    l1[n*(n-1-b)+a]=s[k];
    l2[n*(n-1-a)+(n-1-b)]=s[k];
    r1[n*b+(n-1-a)]=s[k];
}
//string s01=l1;
//string s02=l2;
//string s03=r1;
int cnt[]={0,1,2,1};
for (int i = 0; i < n*n; i++){
    if(s[i]!=t[i]){cnt[0]++;}
    if(l1[i]!=t[i]){cnt[1]++;}
    if(l2[i]!=t[i]){cnt[2]++;}
    if(r1[i]!=t[i]){cnt[3]++;}
}
int min=0;
min = cnt[0]<cnt[1] ? cnt[0]:cnt[1];
min = min<cnt[2] ? min:cnt[2];
min = min<cnt[3] ? min:cnt[3];
cout<<min<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4336
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
using namespace std;
int main(void){
int n;
cin>>n;
string r = "";
string s = "";
string t = "";
for (int i = 0; i < n; i++){cin>>r;s += r;}
for (int i = 0; i < n; i++){cin>>r;t += r;}
char l1[n*n];
char l2[n*n];
char r1[n*n];
int a;int b;
for (int k = 0; k < n*n; k++){
    a=k/n;b=k%n;
    l1[n*(n-1-b)+a]=s[k];
    l2[n*(n-1-a)+(n-1-b)]=s[k];
    r1[n*b+(n-1-a)]=s[k];
}
string s01=l1;
string s02=l2;
string s03=r1;
int cnt[]={0,1,2,1};
for (int i = 0; i < n*n; i++){
    if(s[i]!=t[i]){cnt[0]++;}
    if(s01[i]!=t[i]){cnt[1]++;}
    if(s02[i]!=t[i]){cnt[2]++;}
    if(s03[i]!=t[i]){cnt[3]++;}
}
int min=0;
min = cnt[0]<cnt[1] ? cnt[0]:cnt[1];
min = min<cnt[2] ? min:cnt[2];
min = min<cnt[3] ? min:cnt[3];
cout<<min<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 5584
final_rank: 13

code_snippet: #include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
string r = "";
string s = "";
string t = "";
for (int i = 0; i < n; i++){cin>>r;s += r;}
for (int i = 0; i < n; i++){cin>>r;t += r;}
char l1[n*n];
char l2[n*n];
char r1[n*n];
int a;int b;
for (int k = 0; k < n*n; k++){
    a=k/n;b=k%n;
    l1[n*(n-1-b)+a]=s[k];
    l2[n*(n-1-a)+(n-1-b)]=s[k];
    r1[n*b+(n-1-a)]=s[k];
}
string s01=l1;
string s02=l2;
string s03=r1;
int cnt[]={0,1,2,1};
for (int i = 0; i < n*n; i++){
    if(s[i]!=t[i]){cnt[0]++;}
    if(s01[i]!=t[i]){cnt[1]++;}
    if(s02[i]!=t[i]){cnt[2]++;}
    if(s03[i]!=t[i]){cnt[3]++;}
}
int min=0;
min = cnt[0]<cnt[1] ? cnt[0]:cnt[1];
min = min<cnt[2] ? min:cnt[2];
min = min<cnt[3] ? min:cnt[3];
cout<<min<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 5608
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int N; cin >> N;
	vector<string> S(N), T(N);
	for (auto& s : S) cin >> s;
	for (auto& t : T) cin >> t;
	vector<int> r = {0, 1, 2, 1};
	for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
		if (S[i][j] != T[i][j]) ++r[0];
		if (S[i][j] != T[j][N - 1 - i]) ++r[1];
		if (S[i][j] != T[N - 1 - i][N - 1 - j]) ++r[2];
		if (S[i][j] != T[N - 1 - j][i]) ++r[3];
	}
	cout << *min_element(r.begin(), r.end()) << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4328
final_rank: 6