Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 우분투
- 강의실2
- c#
- 탄막
- mysqld.sock
- 윈도우
- 탄막 스킬 범위
- 영상 프레임 추출
- 걷는건귀찮아
- 2020 KAKAO BLIND RECRUITMENT
- 백준
- 문자열 압축
- MySQL
- 회의실 배정
- 자료구조 목차
- 수 만들기
- 유니티
- 토글 그룹
- 18249
- 탄막 이동
- 마우스 따라다니기
- 알고리즘
- 알고리즘 목차
- AI Hub
- 그리디알고리즘
- 원형
- SWEA
- 3344
- 단어 수학
- 3273
Archives
- Today
- Total
와이유스토리
[누적합] 프로그래머스 파괴되지 않은 건물 C++ 본문
https://school.programmers.co.kr/learn/courses/30/lessons/92344
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
using namespace std;
/*
(0,0) ~ (1,1) n 표시 -> 행별로 열 누적합 -> 열별로 행 누적합
[n, 0, -n, 0] [n, n, 0, 0] [n, n, 0, 0]
[0, 0, 0, 0] [0, 0, 0, 0] [n, n, 0, 0]
[-n, 0, n, 0] [-n, -n, 0, 0] [0, 0, 0, 0]
*/
int solution(vector<vector<int>> board, vector<vector<int>> skill) {
int answer = 0;
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<vector<int>> info;
info.resize(board.size()+1);
for(int i=0; i<board.size()+1; i++) info[i].resize(board[0].size()+1);
// 표시
for(auto s : skill) {
int degree = s[5];
if (s[0] == 1) degree *= (-1);
info[s[1]][s[2]] += degree;
info[s[1]][s[4]+1] += degree * (-1);
info[s[3]+1][s[2]] += degree * (-1);
info[s[3]+1][s[4]+1] += degree;
}
// 행별로 열 누적합
for(int i=0; i<info.size(); i++) {
for(int j=0; j<info[i].size()-1; j++) info[i][j+1] += info[i][j];
}
// 열별로 행 누적합
for(int j=0; j<info[0].size(); j++) {
for(int i=0; i<info.size()-1; i++) info[i+1][j] += info[i][j];
}
for(int i=0; i<board.size(); i++) {
for(int j=0; j<board[i].size(); j++) {
if (board[i][j] + info[i][j] > 0) answer++;
}
}
return answer;
}
'코딩테스트 > 동적계획법' 카테고리의 다른 글
[DP(Top-Down)]백준 1937 욕심쟁이 판다 C++ (0) | 2023.09.04 |
---|---|
[DP(Top-Down)] 백준 2565 전깃줄 C++ (0) | 2023.09.03 |
[누적합] 백준 11660 구간 합 구하기 5 C++ (0) | 2022.02.09 |
[누적합] 백준 11659 구간 합 구하기 4 C++ (0) | 2022.02.09 |
[LIS] (CHECK) 백준 11053 가장 긴 증가하는 부분 수열 C++ (0) | 2022.02.09 |
Comments