실기 답은…

실기 답은 아래와 같을 것이예요. 토마토는 정답 확인 안했는데 맞을 것이예요.

– 그릇
#include

int main() {
char arr[51];

scanf(“%s”, arr);

int height = 10;

for (int p = 1; arr[p] != ”; ++p) {
if (arr[p – 1] == arr[p])
height += 5;
else
height += 10;
}

printf(“%d”, height);
}

– 줄세우기
#include

const int MAXN = 1000005;

int N;

int arr[MAXN];
int dp[MAXN];

int main() {
scanf(“%d”, &N);

for (int i = 0; i < N; ++i)
scanf(“%d”, &arr[i]);

for (int i = 0; i <= N; ++i)
dp[i] = 0;

int ans = 0;
for (int i = 0; i < N; ++i) {
dp[arr[i]] = dp[arr[i] – 1] + 1;
if (ans < dp[arr[i]])
ans = dp[arr[i]];
}

printf(“%dn”, N – ans);
}

– 토마토
#include

const int MAXN = 105;

int M, N, H;

int arr[MAXN][MAXN][MAXN];

int p, q;
int que[2][MAXN * MAXN * MAXN * 3];

const int dx[6] = {1, -1, 0, 0, 0, 0};
const int dy[6] = {0, 0, 1, -1, 0, 0};
const int dz[6] = {0 ,0, 0, 0, 1, -1};

int main() {
int remained = 0;

scanf(“%d%d%d”, &M, &N, &H);

q = 0;
for (int z = 0; z < H; ++z)
for (int y = 0; y < N; ++y)
for (int x = 0; x < M; ++x) {
scanf(“%d”, &arr[z][y][x]);
if (arr[z][y][x] == 1) {
que[0][q++] = z;
que[0][q++] = y;
que[0][q++] = x;
} else if (arr[z][y][x] == 0) {
++remained;
}
}

int f = 1, day = 0, s = 0, t = 1;

p = 0;
while(f) {
if (remained == 0)
break;

f = 0;
while (q > 0) {
int x = que[s][–q];
int y = que[s][–q];
int z = que[s][–q];

for (int i = 0; i < 6; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
int nz = z + dz[i];
if (nx < 0 || nx >= M || ny < 0 || ny >= N || nz < 0 || nz >= H)
continue;
if (arr[nz][ny][nx]== 0) {
que[t][p++] = nz;
que[t][p++] = ny;
que[t][p++] = nx;
–remained;
arr[nz][ny][nx] = 1;
f = 1;
}
}
}

q = p; p = 0;
s = t; t = 1 – t;
++day;
}

if (remained > 0) {
printf(“-1n”);
} else {
printf(“%dn”, day);
}
}