Codeforces Round #238 (Div. 2), problem: (B) Domino Effect:
http://codeforces.com/contest/405/problem/B
Codeforces Round #238 (Div. 2), problem: (B) Domino Effect solution:
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n, r, l, ans, cnt;
ans=cnt=r=l=0;
char s[3005];
scanf("%d", &n);
scanf("%s", s);
for(int i=0; i<n; i++) {
if(s[i]=='.' && r==0) cnt++;
if(s[i]=='L') {
cnt=0;
r=0;
}
if(s[i]=='R') {
ans+=cnt;
cnt=0;
r=1;
}
}
if(cnt>0) ans+=cnt, cnt=0;
r=l=0;
for(int i=0; i<n; i++) {
if(s[i]=='R') r=1;
if(s[i]=='.' && r==1) cnt++;
if(s[i]=='L') {
if(cnt%2==1) ans++;
cnt=0;
r=0;
}
}
printf("%d", ans);
return 0;
}
No comments:
Post a Comment