#include <bits/stdc++.h>
using namespace std;
vector<queue<int>> hi[3000];
queue<int> lo[3000];
int h, k, r, task, ret;
int parse(int num) {
if (num % 2 == 0) return 1;
else return 0;
}
int main(int argc, char** argv)
{
cin >> h >> k >> r;
for (int i=1; i<pow(2, h)*2; i++) {
queue<int> tmp, tmp2;
hi[i].push_back(tmp);
hi[i].push_back(tmp2);
}
for (int i=pow(2, h); i<pow(2, h)*2; i++) {
for (int j=0; j<k; j++) {
cin >> task;
lo[i].push(task);
}
}
while (r--) {
// 상사 업무 처리
for (int i=1; i<pow(2, h); i++) {
if (i == 1) {
if (r % 2 == 0 && hi[i][0].size()) {
ret += hi[i][0].front(), hi[i][0].pop();
} else if (r % 2 != 0 && hi[i][1].size()) {
ret += hi[i][1].front(), hi[i][1].pop();
}
} else {
if (r % 2 == 0 && hi[i][0].size()) {
hi[i/2][parse(i)].push(hi[i][0].front()), hi[i][0].pop();
} else if (r % 2 != 0 && hi[i][1].size()) {
hi[i/2][parse(i)].push(hi[i][1].front()), hi[i][1].pop();
}
}
}
// 말단 업무 처리
for (int i=pow(2, h); i<pow(2, h)*2; i++) {
if (lo[i].size()) {
hi[i/2][parse(i)].push(lo[i].front()), lo[i].pop();
}
}
}
cout << ret << "\n";
return 0;
}
상사는 hi에, 말단은 lo에 넣고 while문 안에서 상사 처리와 말단 처리를 반복했습니다.
subtask 2 의 02_2번만 오답이 뜨는데 대체 어디서 뜨는 것인지 감조차 못 잡겠습니다.
반례를 떠올릴 수 있는 힌트라도 주고 가시면 감사드리겠습니다.