Submission #43122178


Source Code Expand

#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,s,e) for(ll i=s;i<=e;++i)
#define FFOR(i,s,e) for(ll i=s;i>=e;--i)

#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define ALL(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define vl vector<ll>
#define vs vector<string>
#define so(a) sort(a.begin(),a.end())

#define fi first
#define se second
#define print(a) cout<<a<<endl
#define ssize(a) (ll)(a.size())

#define MAX_N 1002
#define i197 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


const ll INF=1000000000000000001;
struct edge
{
	int to, cost;
};

struct pos{
	// 1 変数を入れる;
	ll t;
	ll x,y;
	set<ll> st;

};
int dx[4] = { 1, 0, -1, 0};
int dy[4] = { 0, 1, 0, -1};
int dd[5] = { 0, 1, 0, -1, 0};

typedef pair<ll, ll> P1;
typedef pair<pair<ll,ll>,ll> P3;
typedef pair<string,ll> Ps;
typedef pair<pair<ll,ll>,pair<ll,ll> > P4;

typedef pair<long double,ll> P2;



int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n;
	cin>>n;

	vl a(n+5);
	char c[n+5];

	rep(i,n)cin>>a[i+1];
	rep(i,n)cin>>c[i+1];

	vl d1(4);
	ll d[3][3]={};

	ll ans=0;
	FOR(i,1,n){
		if(c[i]=='M'){
			d1[a[i]]++;
		}else if(c[i]=='E'){
			rep(j,3){
				ll j1=j;
				ll j2=a[i];
				if(j2<j1)swap(j1,j2);
				d[j1][j2]+=d1[j];
			}
		}else{
			rep(j,3){
				rep(k,3){
					if(d[j][k]==0)continue;
					vl b(4);
					b[a[i]]=1;
					b[j]=1;
					b[k]=1;
					rep(l,4){
						if(b[l]==0){
							ans+=l*d[j][k];
							break;
						}
					}
				}
			}

		}
	}

	print(ans);










	return 0;
}


Submission Info

Submission Time
Task E - MEX
User akarinkof
Language C++ (GCC 9.2.1)
Score 475
Code Size 1953 Byte
Status AC
Exec Time 36 ms
Memory 5056 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 03_zero_00.txt, 03_zero_01.txt, 03_zero_02.txt, 04_handmade_00.txt, 04_handmade_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 8 ms 3548 KiB
00_sample_01.txt AC 2 ms 3516 KiB
00_sample_02.txt AC 2 ms 3516 KiB
01_random_00.txt AC 29 ms 4960 KiB
01_random_01.txt AC 23 ms 4964 KiB
01_random_02.txt AC 30 ms 5056 KiB
01_random_03.txt AC 22 ms 4996 KiB
01_random_04.txt AC 25 ms 4960 KiB
01_random_05.txt AC 23 ms 5048 KiB
01_random_06.txt AC 35 ms 5040 KiB
01_random_07.txt AC 34 ms 5048 KiB
01_random_08.txt AC 32 ms 4992 KiB
01_random_09.txt AC 33 ms 4892 KiB
01_random_10.txt AC 33 ms 4892 KiB
01_random_11.txt AC 30 ms 4968 KiB
01_random_12.txt AC 29 ms 5036 KiB
01_random_13.txt AC 32 ms 4964 KiB
01_random_14.txt AC 33 ms 5000 KiB
01_random_15.txt AC 34 ms 5040 KiB
01_random_16.txt AC 32 ms 4964 KiB
01_random_17.txt AC 36 ms 5044 KiB
01_random_18.txt AC 33 ms 4892 KiB
01_random_19.txt AC 33 ms 4988 KiB
02_random2_00.txt AC 18 ms 5000 KiB
02_random2_01.txt AC 23 ms 4888 KiB
02_random2_02.txt AC 28 ms 4892 KiB
03_zero_00.txt AC 19 ms 4996 KiB
03_zero_01.txt AC 30 ms 4996 KiB
03_zero_02.txt AC 19 ms 4956 KiB
04_handmade_00.txt AC 2 ms 3512 KiB
04_handmade_01.txt AC 24 ms 4988 KiB