AOJ 1005 - Advanced Algorithm Class

the elements of the matrix may not be necessarily distinct(要素が必ずしも異ならない)と書いてあったので,
高さが最も(小さい/大きい)人が2人以上いるかもと考えた(杞憂?)
また,studentなので1人に定まるんだろうなとか考えてた.

#include<iostream>
#include<vector>
#include<algorithm>

struct P{
	int x, y;
};

bool operator==(const P& lp, const P& rp){
	return (lp.x == rp.x) && (lp.y == rp.y);
}

const int INF = 1 << 24;

int main(){
	int matrix[100][100];
	int n;
	while(std::cin >> n, n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				std::cin >> matrix[i][j];
			}
		}

		std::vector<P> sv, tv, temp_v;
		for(int i=0;i<n;i++){
			int s_height = INF;
			for(int j=0;j<n;j++){
				if(matrix[i][j] < s_height){
					temp_v.clear();
					temp_v.push_back({j, i});
					s_height = matrix[i][j];
				}else if(matrix[i][j] == s_height){
					temp_v.push_back({j, i});
				}
			}
			for(int k=0;k<temp_v.size();k++){
				sv.push_back(temp_v[k]);
			}
			temp_v.clear();

			int t_height = 0;
			for(int j=0;j<n;j++){
				if(matrix[j][i] > t_height){
					temp_v.clear();
					temp_v.push_back({i, j});
					t_height = matrix[j][i];
				}else if(matrix[j][i] == t_height){
					temp_v.push_back({i, j});
				}
			}
			for(int k=0;k<temp_v.size();k++){
				tv.push_back(temp_v[k]);
			}
			temp_v.clear();
		}

		int res = 0;
		for(int i=0;i<sv.size();i++){
			P p = sv[i];
			if(std::find(tv.begin(), tv.end(), p) != tv.end()){
				res = matrix[p.y][p.x];
				break;
			}
		}

		std::cout << res << std::endl;
	}
}