Created
January 22, 2019 10:40
-
-
Save fpdjsns/0d201929d53ab19e6a8fe943a623f04d to your computer and use it in GitHub Desktop.
[Qualification Round 2017] Problem A. Oversized Pancake Flipper : https://code.google.com/codejam/contest/3264486/dashboard
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
// | |
// Created by fpdjsns on 2019. 1. 22 | |
// Copyright © 2019 fpdjsns. All rights reserved. | |
// | |
/* | |
* 시간복잡도 : O(T * |S| * K) | |
* 공간복잡도 : O(|S|) | |
*/ | |
#include<iostream> | |
#include<string> | |
#include<map> | |
#include<algorithm> | |
using namespace std; | |
int main() { | |
int T; | |
cin >> T; | |
for (int t = 1; t <= T; t++) { | |
string S; | |
int K; | |
cin >> S >> K; | |
int answer = 0; | |
for (int i = 0; i < S.size(); i++) { | |
if (S[i] == '+') continue; | |
if (S.size() < i + K) { | |
answer = -1; | |
break; | |
} | |
else { | |
answer++; | |
for (int j = i; j < i + K; j++) { | |
if (S[j] == '+') S[j] = '-'; | |
else S[j] = '+'; | |
} | |
} | |
} | |
if (answer == -1) printf("Case #%d: IMPOSSIBLE\n", t); | |
else printf("Case #%d: %d\n", t, answer); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment