inlineintread() { int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*f; }
constint N=400005;
int nodes[2][N]; char str[N]; int a[N]; int n,ans,cnt;
voidgreedy() { if (!nodes[0][0]) { ans=nodes[1][0]>0; return; } ans=nodes[0][0]; int head=1,tail=nodes[1][0]; if (nodes[1][0]>nodes[0][0]) { if (nodes[1][head]<nodes[0][1]) ++ans,++head; if (head<=tail&&nodes[1][tail]>nodes[0][nodes[0][0]]) ++ans,--tail; } elseif (nodes[1][head]<nodes[0][1]) ++ans,++head; elseif (nodes[1][tail]>nodes[0][nodes[0][0]]) ++ans,--tail; for (int i=1;i<nodes[0][0];++i) { for (;head<=tail&&nodes[1][head]<nodes[0][i];++head); ans+=head<=tail&&nodes[1][head]<nodes[0][i+1]; } }
intmain() { freopen("game.in","r",stdin),freopen("game.out","w",stdout); n=read(),scanf("%s",str),cnt=0; for (int i=0;i<n;++i) cnt+=str[i]=='B'||str[i]=='R'; for (int i=1,x;i<=n;++i) x=(str[i-1]=='B'||str[i-1]=='R')^(cnt*2<=n),nodes[x][++nodes[x][0]]=read(); for (int i=0;i<2;++i) sort(nodes[i]+1,nodes[i]+1+nodes[i][0]); greedy(),printf("%d\n",ans); fclose(stdin),fclose(stdout); return0; }
参考文献
1 2 3 4 5 6
@inproceedings{Lin2012FindingAL, title={Finding a Longest Increasing Subsequence from the Paths in a Complete Bipartite Graph}, author={Guan-Yu Lin and Jia-Jie Liu and Yue-Li Wang}, year={2012}, url={https://api.semanticscholar.org/CorpusID:18850482} }