-
Notifications
You must be signed in to change notification settings - Fork 0
/
2017_quali_proba.cpp
48 lines (42 loc) · 1.12 KB
/
2017_quali_proba.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "codejam.h"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class codejam2: public virtual codejam{
public:
codejam2(int argc, char** argv): codejam(argc,argv){}
void flip(string& str, size_t index, size_t size){
for (size_t i = index; i < index+size; ++i){
if (str[i] == '+') str[i] = '-';
else str[i] = '+';
}
}
virtual int thread(){
string cakerow;
size_t flipsize;
codejam::input_stream >> cakerow >> flipsize;
size_t result = 0, i;
for (i = 0; i < cakerow.size()+1-flipsize; ++i){
if (cakerow[i]=='-'){
++result;
flip(cakerow,i,flipsize);
}
}
for (; i < cakerow.size(); ++i){
if (cakerow[i]=='-'){
result=-1;
break;
}
}
if (result != -1) codejam::output_stream << result;
else codejam::output_stream << "IMPOSSIBLE";
return 0;
}
};
int main(int argc, char** argv){
codejam2 program(argc,argv);
program.exec();
return 0;
}