제민
영덕대게와 울진대게 본문
처음 문제를 보고 시간 초과를 걱정했는데 입력 조건에 큰 수가 없어서 다행이라고 생각했다.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
int sum(vector<vector<int>>& matrix,int row,int col,int mang){
int sum=0;
for(int i=row; i<row+mang;i++){
for(int j=col; j<col+mang; j++){
sum += matrix[i][j];
}
}
return sum;
}
int main() {
vector<vector<int>> arr;
vector<int> sums;
int n,m,temp=0;
cin >> n >> m;
arr.resize(n,vector<int>(n));
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin >> arr[i][j];
}
}
/*
00 01 02 03 04
10 11 12 13 14
20 21 22 23 24
*/
// arr[세로][가로]
for(int i=0; i<n-m+1;i++){ //아래로 내려감
for(int j=0; j<n-m+1;j++){ //오른쪽으로 이동함
temp = sum(arr,i,j,m);
sums.push_back(temp);
//cout << i << " " << j << " 에서의 합은 " << temp << "\n";
}
}
sort(sums.rbegin(),sums.rend());
cout << sums[0];
return 0;
}
영덕대게와 울진대게 1과의 차이점은 그물 한 변의 길이를 주었다는 것인데, 어려운 문제는 아니었다.