본문 바로가기
백준

[9455] 박스

by Jcoder 2018. 8. 19.


#include <iostream>
using namespace std;
int main()
{
int testcase, m, n, sum, cnt, i ,j;
int arr[101][101] = { 0 };
cin >> testcase;
while (testcase--)
{
cin >> m >> n;
sum = 0;
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++)
cin >> arr[i][j];
for (j = 1; j <= n; j++)
{
for (i = m; i >= 1; i--)
{
cnt = 0;
if (arr[i][j] == 1)
{
for (int k = i + 1; k <= m; k++)
{
if (arr[k][j] == 1)
break;
else
cnt++;
}
sum += cnt;
swap(arr[i + cnt][j], arr[i][j]);
}
}
}
cout << sum << '\n';
}
return 0;
}


'백준' 카테고리의 다른 글

[1269] 대칭 차집합  (0) 2018.08.21
[9971] The Hardest Problem Ever  (0) 2018.08.19
[13240] chessboard  (0) 2018.08.19
[2506] 점수계산  (0) 2018.08.19
[12778] CTP공국으로 이민 가자  (0) 2018.08.18