Last active
January 30, 2019 14:27
-
-
Save Yimyujin/f2ca0df101e4c3bba2f8011aad9160f8 to your computer and use it in GitHub Desktop.
[Codejam_2017]Problem A_Oversized Pancake Flipper.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma warning (disable:4996) | |
/* | |
* 메모리 : O(S) | |
* 시간 : O(N*K) | |
*/ | |
#include <stdio.h> | |
int T, k; | |
char pancake[1001]; | |
int pancake_len; | |
int get_strlen(char *p) { | |
int len = 0; | |
while (*p++) len++; | |
return len; | |
} | |
int solve() { | |
int ix = 0; | |
int cnt = 0; | |
for (; ix + k - 1 < pancake_len; ++ix) { | |
if (pancake[ix] == '-') { | |
for (int j = 0; j < k; ++j) { | |
if (pancake[ix + j] == '+') { | |
pancake[ix + j] = '-'; | |
} | |
else { | |
pancake[ix + j] = '+'; | |
} | |
} | |
cnt++; | |
} | |
} | |
for (int i = ix; i < pancake_len; ++i) { | |
if (pancake[i] == '-') return -1; | |
} | |
return cnt; | |
} | |
int main() { | |
scanf("%d", &T); | |
for (int i = 0; i < T; ++i) { | |
scanf("%s", &pancake); | |
scanf("%d", &k); | |
pancake_len = get_strlen(pancake); | |
int result = solve(); | |
printf("Case #%d:", i + 1); | |
if (result == -1) { | |
printf(" IMPOSSIBLE\n"); | |
} | |
else { | |
printf(" %d\n", result); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment