提交时间:2023-12-31 15:36:01

运行 ID: 34011

#include"bits/stdc++.h" using namespace std; int a[1000000],b[1000000]; int main(){ int n,m,t1=0,p1=0,t2=0,p2=0,x,ans=0; char y; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>x>>y; if(y=='L'){ while(x--){ t1--; p1++; a[p1]+=t1; }} else{ while(x--){ t1++; p1++; a[p1]+=t1; }}} for(int i=1;i<=m;i++){ cin>>x>>y; if(y=='L'){ while(x--){ t2--; p2++; b[p2]+=t2; }} else{ while(x--){ t2++; p2++; b[p2]+=t2; }}} for(int i=1;i<=1000000;i++){ if(i>p1)a[i]=t1; if(i>p2)b[i]=t2; if(a[i]==b[i]&&a[i-1]!=b[i-1])ans++;} cout<<ans;}