# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1053413 | Dennis_Jason | Miners (IOI07_miners) | C++14 | 1006 ms | 1372 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define NMAX 100001
#define int long long
#define pb push_back
#define eb emplace_back
#define MOD 1000000007
#define nl '\n'
#define INF 1000000007
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int,int>
//#pragma GCC optimize("O3")
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
/*
*
*
----------------DEMONSTRATION-------------------
MBMFFB
mine1 mine2
MBF MFB
1+2+3=6 1+2+3=6
MBMFFB
---------------------END------------------------
*/
/*-------------Initialize------------*/
int n;
string s;
int v[NMAX];
int res=0;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
cin>>s;
v[0]=0;
for(int i=1;i<=n;++i)
{
if(s[i-1]=='M')
v[i]=1;
else if(s[i-1]=='F')
v[i]=2;
else
v[i]=3;
map<int,int>mp;
if(v[i])
mp[v[i]]++;
if(v[i-1])
mp[v[i-1]]++;
if(v[i-2])
mp[v[i-2]]++;
if(mp.size()==1)
res+=1;
else if(mp.size()==2)
res+=2;
else
res+=3;
}
if(n<=20)
{
int MSK=(1<<n);
for(int mask=0;mask<MSK;++mask)
{
vector<int>ind1;
vector<int>ind2;
int new_mask=((MSK-1)^mask);
int aux_msk=mask;
if(new_mask>aux_msk)
swap(new_mask,aux_msk);
for(int bit=0;bit<n;++bit)
{
if(aux_msk&(1<<bit))
{
ind1.pb(bit+1);
}
}
for(int bit=0;bit<n;++bit)
{
if(new_mask&(1<<bit))
{
ind2.pb(bit+1);
}
}
// if(mask==47119)
// {
// for(auto x:ind1)
// cout<<x<<" ";
// }
int aux=0;
for(int i=0;i<ind1.size();++i)
{
map<int,int>mp;
if(i>=0)
mp[v[ind1[i]]]++;
if(i-1>=0)
mp[v[ind1[i-1]]]++;
if(i-2>=0)
mp[v[ind1[i-2]]]++;
if(mp.size()==1)
aux+=1;
else if(mp.size()==2)
aux+=2;
else
aux+=3;
}
for(int i=0;i<ind2.size();++i)
{
map<int,int>mp;
if(i>=0)
mp[v[ind2[i]]]++;
if(i-1>=0)
mp[v[ind2[i-1]]]++;
if(i-2>=0)
mp[v[ind2[i-2]]]++;
if(mp.size()==1)
aux+=1;
else if(mp.size()==2)
aux+=2;
else
aux+=3;
}
res=max(res,aux);
}
cout<<res;
}
return 0;
}
Compilation message (stderr)
# | 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... |
# | 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... |
# | 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... |