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 <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
#include <random>
typedef long long ll;
const ll MOD = 1e9 + 7, INF = 1e18;
using namespace std;
int n;
struct state
{
int a, b, c, d;
};
int encode (state s)
{
return s.a * 64 + s.b * 16 + s.c * 4 + s.d;
}
state decode (int s)
{
state a;
a.a = s / 64;
s %= 64;
a.b = s / 16;
s %= 16;
a.c = s / 4;
s %= 4;
a.d = s;
return a;
}
int value (state s, int a, bool left)
{
int ans = 0;
if (left)
{
if (s.a == 1 || s.b == 1 || a == 1) ans++;
if (s.a == 2 || s.b == 2 || a == 2) ans++;
if (s.a == 3 || s.b == 3 || a == 3) ans++;
}
else
{
if (s.c == 1 || s.d == 1 || a == 1) ans++;
if (s.c == 2 || s.d == 2 || a == 2) ans++;
if (s.c == 3 || s.d == 3 || a == 3) ans++;
}
return ans;
}
state transfer (state s, int k, bool left)
{
if (left)
{
s.a = s.b;
s.b = k;
}
else
{
s.c = s.d;
s.d = k;
}
return s;
}
int d[100000][256], u[100000][256];
int main ()
{
cin >> n;
string s;
cin >> s;
string h (1, s[0]);
state en;
if (s[0] == 'M') en.b = 1;
if (s[0] == 'B') en.b = 2;
if (s[0] == 'F') en.b = 3;
en.a = en.c = en.d = 0;
d[1][encode (en)] = 1;
u[1][encode (en)] = 1;
int mx = 1;
for (int i = 1; i < s.length (); i++)
{
for (int j = 0; j < 256; j++)
{
if (!u[i][j]) continue;
state dec = decode (j);
int cur = 0;
if (s[i] == 'M') cur = 1;
if (s[i] == 'B') cur = 2;
if (s[i] == 'F') cur = 3;
int b = encode (transfer (dec, cur, true));
u[i + 1][b] = 1;
d[i + 1][b] = max (d[i + 1][b], value (dec, cur, true) + d[i][j]);
mx = max (mx, d[i + 1][b]);
b = encode (transfer (dec, cur, false));
u[i + 1][b] = 1;
d[i + 1][b] = max (d[i + 1][b], value (dec, cur, false) + d[i][j]);
mx = max (mx, d[i + 1][b]);
}
}
cout << mx;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:106:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < s.length (); i++)
~~^~~~~~~~~~~~~
# | 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... |