Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

// dp[n-1][bits] := 最小のmyonの回数
vector<char> dp[3];
// dp_4[bits] := n が 4 のときの最小のmyonの回数
map<int,char> dp_4;
// dp_5[bits] := n が 5 のときの最小のmyonの回数
map<int,char> dp_5;

// (x,y) の値(0 or 1) を返す
int get(int n, int bits, int x, int y){
	return ((bits & (1 << (x+y*n))) > 0 );
}

void debug(int bits, int n){
	cout << "debug : " << endl;
	for(int y=0 ; y < n ; y++ ){
		for(int x=0 ; x < n ; x++ ){
			cout << get(n,bits,x,y);
		}
		cout << endl;
	}
	cout << endl;
}

// [(sx,sy),(gx,gy)] の範囲に myon をかける (0 <=> 1 の反転)
int myon(int bits, int n, int sx, int sy, int gx, int gy){
	for(int y = sy ; y <= gy ; y++ ){
		for(int x = sx ; x <= gx ; x++ ){
			int k = 1 << (x+y*n);
			(bits & k)? bits -= k : bits += k;
		}
	}
	return bits;
}

// n = 3 のときのすべての状態からの最小の myon の回数を計算する
// n*n のすべて 0 の状態からBFS
void solve_2(int n){
	queue< pair<int,char> > q;
	q.push( pair<int,char>( 0 , 0 ) );
	map<int,bool> memo;
	
	while( !q.empty() ){
		int bits = q.front().first; 
		char cnt = q.front().second;
		q.pop();
		if( memo[bits] ) continue;
		memo[bits] = true;
		dp[n-1][bits] = cnt;
		
		for(int y = 0 ; y < n ; y++ ){
			for(int x = 0 ; x < n ; x++ ){
				for(int my = y ; my < n ; my++ ){
					for(int mx = x ; mx < n ; mx++){
						int next = myon( bits , n , x , y , mx , my );
						if( !memo[next] ){
							q.push( pair<int,char>( next , cnt+1 ) );
						}
					}
				}
			}
		}
	}
}

// n = 4 のときの一部の最小の myon の回数を計算する
// n*n のすべて 0 の状態からBFS (2手以下まで)
void solve_3(){
	queue< pair<int,char> > q;
	q.push( pair<int,char>( 0 , 0 ) );
	map<int,bool> memo;
	
	while( !q.empty() ){
		int bits = q.front().first; 
		char cnt = q.front().second;
		q.pop();
		if( memo[bits] ) continue;
		memo[bits] = true;
		
		dp_4[bits] = cnt;
		
		if( dp_4.size() >= 10000 ) break;
		
		for(int y = 0 ; y < 4 ; y++ ){
			for(int x = 0 ; x < 4 ; x++ ){
				for(int my = y ; my < 4 ; my++ ){
					for(int mx = x ; mx < 4 ; mx++){
						int next = myon( bits , 4 , x , y , mx , my );
						if( !memo[next] ){
							q.push( pair<int,int>( next , cnt+1 ) );
						}
					}
				}
			}
		}
	}
}

// n = 5 のときの一部の最小の myon の回数を計算する
// n*n のすべて 0 の状態からBFS (2手以下まで)
void solve_4(){
	queue< pair<int,char> > q;
	q.push( pair<int,char>( 0 , 0 ) );
	map<int,bool> memo;
	
	while( !q.empty() ){
		int bits = q.front().first; 
		char cnt = q.front().second;
		q.pop();
		if( memo[bits] ) continue;
		memo[bits] = true;
		
		dp_5[bits] = cnt;
		
		if( dp_5.size() >= 10000 ) break;
		
		for(int y = 0 ; y < 5 ; y++ ){
			for(int x = 0 ; x < 5 ; x++ ){
				for(int my = y ; my < 5 ; my++ ){
					for(int mx = x ; mx < 5 ; mx++){
						int next = myon( bits , 5 , x , y , mx , my );
						if( !memo[next] ){
							q.push( pair<int,int>( next , cnt+1 ) );
						}
					}
				}
			}
		}
	}
}

// n <= 4 のときのまだ求めていないときに BFS で求める
/*int bfs(int bits, int n){
	queue< pair<int,char> > q;
	q.push( pair<int,char>( bits , 0 ) );
	map<int,bool> memo;
	
	while( !q.empty() ){
		int bits = q.front().first; 
		char cnt = q.front().second;
		q.pop();
		
		if( q.size() + memo.size() >= 20000 ){
			return 3;
		}
		
		if( n == 4 ){
			if( dp_4.count(bits) ){
				return dp_4[bits] + cnt;
			}
		}else if( n == 5 ){
			if( dp_5.count(bits) ){
				return dp_5[bits] + cnt;
			}
		}
		
		if( memo[bits] ) continue;
		memo[bits] = true;
		
		for(int y = 0 ; y < n ; y++ ){
			for(int x = 0 ; x < n ; x++ ){
				for(int my = y ; my < n ; my++ ){
					for(int mx = x ; mx < n ; mx++){
						int next = myon( bits , n , x , y , mx , my );
						if( !memo[next] ){
							q.push( pair<int,int>( next , cnt+1 ) );
						}
					}
				}
			}
		}
	}
}*/


int dfs(int bits, int n, int cnt){
	if( n == 4 ){
		if( dp_4.count(bits) ){
			return dp_4[bits] + cnt;
		}
	}else if( n == 5 ){
		if( dp_5.count(bits) ){
			return dp_5[bits] + cnt;
		}
	}
	
	for(int y = 0 ; y < n ; y++ ){
		for(int x = 0 ; x < n ; x++ ){
			for(int my = y ; my < n ; my++ ){
				for(int mx = x ; mx < n ; mx++){
					int next = myon( bits , n , x , y , mx , my );
					dfs( next , n , cnt + 1 );
				}
			}
		}
	}
	
}

// n <= 4 のすべての解と n = 5 の一部の解を求めておく
void solve(){
	for(int i=0 ; i < 5 ; i++ ){
		if( i == 0 ){
			vector<char> v(2);
			v[0] = 0;
			v[1] = 1;
			dp[0] = v;
		}else if( i == 1 ){
			vector<char> v(16);
			int f[16] = {0,1,1,1,1,1,2,2,1,2,1,2,1,2,2,1};
			for(int j=0 ; j < 16 ; j++ ){
				v[j] = f[j];
			}
			dp[1] = v;
		}else if( i == 2 ){
			vector<char> v(512);
			dp[2] = v;
			solve_2( 3 );
		}else if( i == 3 ){
			//vector<char> v(65536);
			//dp[3] = v;
			//solve_2( 4 );
			solve_3();
		}else if( i == 4 ){
			solve_4();
		}
	}
}

int main(){
	// n <= 4 のすべての解と n = 5 の一部の解を求めておく
	solve();
	
	//cout << "dp_5.size() : " << dp_5.size() << endl;
	//cout << "input" << endl;
	
	string s[5] = { "" , "myon" , "myonmyon", "myonmyonmyon", "myonmyonmyonmyon"};
	
	int n;
	while( cin >> n , n ){
		int bits = 0;
		
		for(int i=0 ; i < n*n ; i++ ){
			int b;
			cin >> b;
			bits |= (b << i);
		}
		
		// debug( bits , n );
		
		int ans = 0;
		if( n <= 3 ){
			cout << s[ dp[n-1][bits] ] << endl;
		}else if( n == 4 ){
			if( dp_4.count(bits) )
				cout << s[ dp_4[bits] ] << endl;
			else
				cout << s[ dfs(bits,n) ] << endl;
		}else if( n == 5 ){
			if( dp_5.count(bits) )
				cout << s[ dp_5[bits] ] << endl;
			else
				cout << s[ dfs(bits,n) ] << endl;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:264:47: error: too few arguments to function 'int dfs(int, int, int)'
  264 |                                 cout << s[ dfs(bits,n) ] << endl;
      |                                            ~~~^~~~~~~~
a.cc:182:5: note: declared here
  182 | int dfs(int bits, int n, int cnt){
      |     ^~~
a.cc:269:47: error: too few arguments to function 'int dfs(int, int, int)'
  269 |                                 cout << s[ dfs(bits,n) ] << endl;
      |                                            ~~~^~~~~~~~
a.cc:182:5: note: declared here
  182 | int dfs(int bits, int n, int cnt){
      |     ^~~
a.cc: In function 'int dfs(int, int, int)':
a.cc:204:1: warning: control reaches end of non-void function [-Wreturn-type]
  204 | }
      | ^