728x90
#include<iostream>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
vector<vector<int>>arr(5, vector<int>(5));
bool check[5][5];
map<int, int> rowm;
map<int, int> colm;
map<int, int> diagm;
bool checkRow(int row) { //행
if (rowm[row]) { return true; }
for (int i = 0; i < 5; i++) {
if (check[row][i] == false) {
return false;
}
}
rowm[row] = true;
return true;
}
bool checkColumn(int col) { //열
if (colm[col]) { return true; }
for (int i = 0; i < 5; i++) {
if (check[i][col] == false) {
return false;
}
}
colm[col] = true;
return true;
}
bool checkDiagnol(int num) { //대각선
if (diagm[num]) { return true; }
if (num == 1) {
for (int i = 0; i < 5; i++) {
if (check[i][i] == false) {
return false;
}
}
}
else {
for (int i = 0; i < 5; i++) {
if (check[i][4-i] == false) {
return false;
}
}
}
diagm[num] = true;
return true;
}
bool isBingo() {
int count = 0;
for (int i = 0; i < 5; i++) {
if (checkRow(i)) { count++; }
if (checkColumn(i)) { count++; }
}
for (int i = 0; i < 2; i++) {
if (checkDiagnol(i)) { count++; }
}
if (count >= 3) { return true; }
else { return false; }
}
int main() {
int num;
int answer = 0;
memset(check, false, sizeof(check));
map<int, pair<int, int>>m;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
cin >> arr[i][j];
m[arr[i][j]] = make_pair(i, j);
}
}
int n;
bool toggle = false;
for (int i = 0; i < 25; i++) {
cin >> n;
int x = m[n].first;
int y = m[n].second;
check[x][y] = true;
if (isBingo() && (toggle == false) ){ answer = i + 1; toggle = true; }
}
cout << answer<<endl;
}