강의

멘토링

커뮤니티

Inflearn Community Q&A

tjsrud4282731's profile image
tjsrud4282731

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

50. Territory selection (small: 2D array brute force)

case2에서만 wrong answer가 뜹니다

Written on

·

231

0

다른 케이스에선 전부 success가 뜨는데 2에서만 틀린이유가 무엇일까요?ㅠ 강의에 나온 코드와 비교해 보아도 딱히 틀린게 없어보입니다.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int h,w,hh,hw,sum,max=-2147000000;
	cin>>h>>w;
	vector <vector <int> > tree (h, vector <int> (w));
	for(int i =0; i<h; i++){
		for(int j = 0; j<w; j++){
			cin>>tree[i][j];
		}
	}
	cin>>hh>>hw;
	for(int i = 0; i<h-hh; i++){
		for(int j = 0; j<w-hw; j++){
			sum = 0;
			for(int x = i; x<i+hh; x++){
				for(int y = j; y<j+hw; y++){
					sum+=tree[x][y];
				}
			}
			if(max<sum){
				max = sum;
			}
		}
	}
	cout<<max;
	return 0;
}
C++코테 준비 같이 해요!

Answer 2

3

codingcamp님의 프로필 이미지
codingcamp
Instructor

tree[h-hh][w-hw] 지점을 생각해보세요. 여기에 답이 있습니다.

0

tjsrud4282731님의 프로필 이미지
tjsrud4282731
Questioner

감사합니다 해결했습니다!!

tjsrud4282731's profile image
tjsrud4282731

asked

Ask a question