显示代码纯文本
#include <iostream>
#include <cstdio>
#include <deque>
#define increment(queue,value) if(! queue.empty()){\
value += (queue.front())?(1):(-1); \
queue.pop_front();\
}
#define inc(x) (x)?(1):(-1)
struct input{
input & operator >>(int & i){
i = 0;
char c = getchar();
while(!(c>='0'&&c<='9')) c = getchar();
while(c>='0'&&c<='9'){i = i * 10 + (c-'0');c = getchar();}
}
input & operator >>(char & c){
c = getchar();
while(!(c=='L'||c=='R')) c = getchar();
}
};
struct deque{
bool data[1000001];
int head,tail;
deque(){
head = tail = 0;
}
void push_back(bool i){
data[tail++] = i;
}
bool front(){
return data[head];
}
void pop_front(){
head++;
}
int size(){
return (tail-head);
}
int empty(){
return (size()==0);
}
};
//using std::cin;
input cin;
using std::cout;
using std::endl;
//using std::deque;
int run(){
int b,e,t,result=0;
int la=0,lb=0,fa,fb,u=1;
char d;
deque action1,action2;
freopen("greetings.in","r",stdin),freopen("greetings.out","w+",stdout);
cin>>b>>e;
for(int x=0;x!=b;x++){
cin>>t>>d;
while(t--) action1.push_back(d=='R');
}
for(int x=0;x!=e;x++){
cin>>t>>d;
while(t--) action2.push_back(d=='R');
}
increment(action1,la);
increment(action2,lb);
while(action1.size()>0||action2.size()>0){
if(u>1000000) break;
fa = la,fb = lb;
increment(action1,la);
increment(action2,lb);
if(fa!=fb&&la==lb) result ++;
u++;
}
cout<<result<<endl;
return 0;
}
int rvalue = run();
int main(int argc,char ** argv){
return 0;
}