이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=4e5;
int mtch[N+10];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int b=2*n-1,w=2*n-1;
	int bw=0,ww=0;
	long long ans=0;
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='B')
		{
			while(s[w]!='W')
			{
				ww+=mtch[w];
				w--;
			}
			//cerr<<"w "<<w<<"\n";
			ans+=ww;
			mtch[w]++;
			if(b<w)
				bw++;
			ww++;
			w--;
		}
		else
		{
			while(s[b]!='B')
			{
				bw+=mtch[b];
				b--;
			}
			//cerr<<"b "<<b<<"\n";
			ans+=bw;
			mtch[b]++;
			if(w<b)
				ww++;
			bw++;
			b--;
		}
		//cerr<<ans<<"\n";
	}
	cout<<ans<<"\n";
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |