Submission #760316

#TimeUsernameProblemLanguageResultExecution timeMemory
760316baneMiners (IOI07_miners)C++17
100 / 100
161 ms516 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <unordered_set> #include <vector> #include <climits> #include <list> using namespace std; using ll = long long; using db = long double; // or double, if TL is tight using llu = unsigned long long; using str = string; // yay python! // pairs using pii = pair<int,int>; using pll = pair<ll,ll>; using pdb = pair<db,db>; #define mp make_pair #define fr first #define sc second #define tcT template<class T #define tcTU tcT, class U // ^ lol this makes everything look weird but I'll try it tcT> using V = vector<T>; tcT, size_t SZ> using AR = array<T,SZ>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<db>; using vs = V<str>; using vpi = V<pii>; using vpl = V<pll>; using vpd = V<pdb>; #define ms0(x) memset(x , 0, sizeof(x)) // vectors // oops size(x), rbegin(x), rend(x) need C++17 #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); } tcT> int upb(V<T>& a, const T& b) { return int(ub(all(a),b)-bg(a)); } // loops #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define rep(a) F0R(_,a) #define each(a,x) for (auto& a: x) const int MOD = (int)1e9+7; // 998244353; const int MX = (int)2e5+5; const ll BIG = 1e18; // not too close to LLONG_MAX const db PI = acos((db)-1); inline namespace FileIO { void setIn(str s) { freopen(s.c_str(),"r",stdin); } void setOut(str s) { freopen(s.c_str(),"w",stdout); } void setIO(str s = "") { cin.tie(0)->sync_with_stdio(0); // unsync C / C++ I/O streams // cin.exceptions(cin.failbit); // throws exception when do smth illegal // ex. try to read letter into int if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for old USACO } } const int dx[4] = {0,1,0,-1}; const int dy[4] = {-1,0,1,0}; int main() { setIO(""); int n; cin >> n; int dp[2][2][4][4][4][4]; string s; cin >> s; memset(dp, -1, sizeof(dp)); map<char,int>mapa; mapa['M'] = 1; mapa['B'] = 2; mapa['F'] = 3; dp[0][0][0][0][0][0] = 0; dp[1][0][0][0][0][0] = 0; dp[1][1][mapa[s[0]]][0][0][0] = 1; dp[1][0][mapa[s[0]]][0][0][0] = 1; for (int i = 1; i<=n; i++){ int x = mapa[s[i - 1]]; //place on the right //kade for (int j = 0; j<2; j++){ for (int l = 1; l<=3; l++){ for (int p = 0; p<=3; p++){ for (int k = 0; k<=3; k++){ for (int m = 0; m<=3; m++){ if (dp[1 - 1][j][l][p][k][m]==-1)continue; int cnt = 0; if (x == 1 || p == 1|| l == 1)++cnt; if (x == 2 || p == 2 || l == 2)++cnt; if (x == 3 || l == 3 || p== 3)++cnt; dp[1][1][x][l][k][m] = max(dp[1][1][x][l][k][m], dp[1 - 1][j][l][p][k][m] + cnt ); } } } } } for (int j = 0; j<2; j++){ for (int l = 1; l<=3; l++){ for (int p = 0; p<=3; p++){ for (int k = 0; k<=3; k++){ for (int m = 0; m<=3; m++){ if (dp[0][j][l][p][k][m]==-1)continue; int cnt = 0; if (x == 1 || k == 1|| m == 1)++cnt; if (x == 2 || k == 2 || m == 2)++cnt; if (x == 3 || k == 3 || m == 3)++cnt; dp[1][0][l][p][x][k] = max(dp[1][0][l][p][x][k], dp[1 - 1][j][l][p][k][m] + cnt ); } } } } } for (int j = 0; j<2; j++){ for (int l = 1; l<=3; l++){ for (int p = 0; p<=3; p++){ for (int k = 0; k<=3; k++){ for (int m = 0; m<=3; m++){ dp[0][j][l][p][k][m] = dp[1][j][l][p][k][m]; } } } } } } int best = 0; for (int j = 0; j<2; j++){ for (int l = 1; l<=3; l++){ for (int p = 0; p<=3; p++){ for (int k = 0; k<=3; k++){ for (int m = 0; m<=3; m++){ best = max(best, dp[1][j][l][p][k][m]); } } } } } cout<<best; }

Compilation message (stderr)

miners.cpp: In function 'void FileIO::setIn(str)':
miners.cpp:82:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     void setIn(str s)  { freopen(s.c_str(),"r",stdin); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
miners.cpp: In function 'void FileIO::setOut(str)':
miners.cpp:83:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...