Problem
Logic
분석
- 문제 유형 (알고리즘…)
- 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도…)
설계
- 알고리즘 선택
- 자료구조 선택
- 수도 코드 작성
- 정합판단
1 ~ 3
과정으로 도출된 로직이 문제를 해결하는가
- 그렇다 → 구현
- 잘 모르겠다 → 구현
- 아니다 → 1번부터 다시 점검
구현
테스트
My Code
cpp
boj/9455.cpp// https://www.acmicpc.net/problem/9455
// https://codeyoma.github.io/Computer-Science/1-Foundations--and--Theory/Algorithms/ps/boj/9455/9455
#include <iostream>
using namespace std;
#ifdef LOCAL
# define LOG clog
#else
struct nullstream : ostream {
nullstream()
: ostream(nullptr) {}
};
nullstream LOG;
#endif
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
//--------------------------------------------------------------------------------------------------
#define MAX (1234567891)
#define MIN (-1234567891)
#include <iostream>
#include <vector>
int main() {
fast_io();
// logic
int t;
cin >> t;
while (t--) {
int m, n;
cin >> m >> n;
vector<vector<bool>> v(m, vector<bool>(n));
for (int x = 0; x < m; ++x) {
for (int y = 0; y < n; ++y) {
int temp;
cin >> temp;
v[x][y] = temp;
}
}
int answer = 0;
for (int x = m - 1; x >= 0; --x) {
for (int y = 0; y < n; ++y) {
if (v[x][y]) {
continue;
}
for (int r = x - 1; r >= 0; --r) {
if (v[r][y]) {
v[r][y] = false;
v[x][y] = true;
answer += x - r;
break;
}
}
}
}
cout << answer << "\n";
}
}