#include #include #include #include #include using namespace std; typedef pair P; // (勝利数, チーム) const int kMAX_N = 6; int N, answer; char S[kMAX_N][kMAX_N]; int result[kMAX_N][kMAX_N]; void Judge() { vector

table; for (int i = 0; i < N; i++) { int win = 0; for (int j = 0; j < N; j++) { if (result[i][j]) win++; } table.push_back(make_pair(win, i)); } sort(table.begin(), table.end(), greater

()); int rank = 1, i = 0; while (i < N) { if (i > 0 && table[i - 1].first != table[i].first) rank++; if (table[i].second == 0) break; i++; } answer = min(answer, rank); } // 有りうる勝敗のパターンを全列挙する void rec(int me, int enemy) { if (me == N) { // 結果判定 Judge(); return; } if (S[me][enemy] == '-') { for (int i = 0; i < 2; i++) { result[me][enemy] = i; result[enemy][me] = (i + 1) % 2; if (enemy == N - 1) rec(me + 1, 0); else rec(me, enemy + 1); } } else { if (S[me][enemy] == 'o') { result[me][enemy] = 1; result[enemy][me] = 0; } else if (S[me][enemy] == 'x') { result[me][enemy] = 0; result[enemy][me] = 1; } if (enemy == N - 1) rec(me + 1, 0); else rec(me, enemy + 1); } } void Solve() { answer = kMAX_N; memset(result, -1, sizeof(result)); rec(0, 0); cout << answer << endl; } int main() { cin >> N; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> S[i][j]; } } Solve(); return 0; }