Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created January 22, 2019 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/0d201929d53ab19e6a8fe943a623f04d to your computer and use it in GitHub Desktop.
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
//
// 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