This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
int x[(int)1e6], n;
int whr[200];
string s(string a , char p){
if(a.length()<3) {
a += p ;
return a ;
}
swap(a[0],a[2]);
swap(a[0],a[1]);
a[2] = p ;
return a;
}
int gain( string a ) {
bool hi[] = { 1 , 0 , 0 , 0 };
int res = 0;
for (auto i:a) {
res += (!hi[(int)i] ? 1 : 0);
hi[(int)i] = true;
}
return res;
}
int SAAD(int idx, string a, string b) {
int mx = 0;
if (idx == n)return 0;
mx = max(SAAD(idx + 1, s( a , char(x[idx]) ), b) + gain(s(a,char(x[idx]))), SAAD(idx + 1, a, s( b , char(x[idx]) )) + gain(s( b,char(x[idx]) )));
//cout << idx << " " << mx << endl << a << " " << b << endl ;
return mx;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
whr['M'] = 1;
whr['B'] = 2;
whr['F'] = 3;
cin >> n;
for (int i = 0; i < n;i++) {
char a;
cin >> a;
x[i] = whr[a];
}
cout << SAAD(0,"","") ;
return 0;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:63:20: warning: array subscript has type 'char' [-Wchar-subscripts]
63 | x[i] = whr[a];
| ^
# | 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... |