Submission #106744

# Submission time Handle Problem Language Result Execution time Memory
106744 2019-04-20T05:51:06 Z SOIVIEONE Miners (IOI07_miners) C++14
100 / 100
1400 ms 244328 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
 
#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}
 
//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
 
int n;
string s;
int c[300];
int a[N*10];
ll dp[4][4][4][4][100000];
ll f(int f1, int s1, int f2, int s2, int id)
{
	if(id >= n)
		return 0;
	if(dp[f1][s1][f2][s2][id] != -1)
		return dp[f1][s1][f2][s2][id];
	set<char> fo, ho;
	fo.insert(a[id]); ho.insert(a[id]);
	if(f1 != 3)	fo.insert(f1);
	if(f2 != 3)	ho.insert(f2);
	if(s1 != 3)	fo.insert(s1);
	if(s2 != 3)	ho.insert(s2);
	ll foo = f(s1, a[id], f2, s2, id + 1) + (ll)(fo.size());
	ll hoo = f(f1, s1, s2, a[id], id + 1) + (ll)(ho.size());
	return dp[f1][s1][f2][s2][id] = max(foo, hoo);
}
 
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n >> s;
	c['B'] = 0;
	c['F'] = 1;
	c['M'] = 2;
	for(int i = 0; i < s.size(); i ++)
		a[i] = c[s[i]];
	cout << f(3, 3, 3, 3, 0);
 
 
 
 
	
 
 
 
 
 
	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Compilation message

miners.cpp: In function 'int main()':
miners.cpp:63:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i ++)
                 ~~^~~~~~~~~~
miners.cpp:64:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   a[i] = c[s[i]];
                ^
# Verdict Execution time Memory Grader output
1 Correct 164 ms 200696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 200828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 200652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 200664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 200784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 200728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 201052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 202652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 205112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 210936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 673 ms 227904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1400 ms 244328 KB Output is correct