반응형
코드
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
int h, w, i, j, t;
int height, width, max = -2147000000;
int p1, p2;
cin >> h >> w;
vector<vector<int>> vInt;
vector<int> temp;
for (i = 0; i < h; ++i)
{
temp.clear();
temp.resize(w);
for (j = 0; j < w; ++j)
{
cin >> temp[j];
}
vInt.push_back(temp);
}
cin >> height >> width;
for (i = 0; i <= h - height; ++i)
{
for (j = 0; j <= w - width; ++j)
{
p1 = 0;
p2 = 0;
t = 0;
while (true)
{
if (p2 >= width)
{
++p1;
p2 = 0;
}
if (p1 >= height) break;
t += vInt[i + p1][j + p2];
p2++;
}
if (max < t) max = t;
}
}
cout << max << endl;
return 0;
}
출력 결과
채점 결과
다음번 문제가 large인데, 절대 통과 못 할 코드다... 간결하고 시간 복잡도 낮은 코드를 짜고 싶다. 😭
해당 포스트는 'it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비' 강의를 수강하며 개인 백업용으로 메모하였습니다.
인프런: https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98#
반응형