Merged
Conversation
Contributor
Author
|
Monotone Deque 돌리는 부분 수정 for (int i = 2; i < N - C + 1; i++) {
deque<pair<int, int>> dq;
for (int j = 2; j < M - D + 1; j++) {
while (!dq.empty() && dq.back().first > crr[i][j]) dq.pop_back();
dq.emplace_back(crr[i][j], j);
while (!dq.empty() && j - dq.front().second >= B - 2 - D + 1) dq.pop_front();
if (j - (B - 2 - D + 1) + 1 >= 2) drr[i][j - (B - 2 - D + 1) + 1] = dq.front().first;
}
}
for (int j = 2; j < M - D + 1; j++) {
deque<pair<int, int>> dq;
for (int i = 2; i < N - C + 1; i++) {
while (!dq.empty() && dq.back().first > drr[i][j]) dq.pop_back();
dq.emplace_back(drr[i][j], i);
while (!dq.empty() && i - dq.front().second >= A - 2 - C + 1) dq.pop_front();
if (i - (A - 2 - C + 1) + 1 >= 2) err[i - (A - 2 - C + 1) + 1][j] = dq.front().first;
}
}최소 누적 합 역추적 부분 수정 int y = -1, z = -1;
for (int i = w + 1; i <= w + A - 2 - C + 1; i++) for (int j = x + 1; j <= x + B - 2 - D + 1; j++) {
if (crr[i][j] == err[w+1][x+1]) {
return cout << x << ' ' << w << '\n' << j << ' ' << i, 0;
}
}두 군데에서 인덱스 이상하게 써서 틀린 거였음,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/5479
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
NM 격자에서 (AB 크기의 직사각형 내에 적힌 수의 합) - (그 안에 C*D 크기의 직사각형 내에 적힌 수의 합) 이 최대가 되도록 하는 직사각형 배치를 구해보자.
🔍 풀이 방법
AB 크기의 누적 합과 CD 크기의 누적 합을 미리 계산해놓는다.
CD 크기의 누적 합 원소들로
Monotone Deque을 두 번 써서 2차원 직사각형 최솟값을 구해놓고, AB 누적 합과의 차이 중 최댓값을 구해줬다.⏳ 회고
왜 틀리지 진짜 모르겠어서 열받는다