Codeforces Round #234 (Div. 2), problem: (B) Inna and New Matrix of Candies:
http://codeforces.com/contest/400/problem/B
Codeforces Round #234 (Div. 2), problem: (B) Inna and New Matrix of Candies solution: http://ideone.com/dryQ7U
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int n, m, c[1005], cnt, a, b, flag;
flag=cnt=0;
memset(c, 0, sizeof(c));
char s[1005];
scanf("%d%d", &n, &m);
for(int j=0; j<n; j++) {
a=0, b=1000;
memset(s, 0, sizeof(s));
scanf("%s\n", s);
for(int i=0; i<m; i++) {
if(s[i]=='G') a=i;
else if(s[i]=='S') b=i;
}
if(b<a) {
flag=1;
break;
}
else {
if(c[b-a]==0) cnt++;
c[b-a]++;
}
if(flag==1) break;
}
if(flag==1) printf("-1\n");
else printf("%d\n", cnt);
return 0;
}
No comments:
Post a Comment