Submission #542100

#TimeUsernameProblemLanguageResultExecution timeMemory
542100MdominykasMiners (IOI07_miners)C++14
92 / 100
1577 ms488 KiB
/*input 16 MMBMBBBBMMMMMBMB */ /*input 6 MBMFFB */ #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <unistd.h> using namespace std; using namespace __gnu_pbds; #define ws(x) cerr << #x << " is " << x << endl typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedTree; typedef long long ll; #define mp make_pair vector<int> decoding[13]; int encode(vector<int> &food) { if(food.size() == 0) return 0; else if (food.size() == 1) return food.back(); else if (food.size() >= 2) return 3 * food[food.size() - 2] + food[food.size() - 1]; } // int encode(vector<int> &food) // { // cout << "encodinu:" << endl; // for(int i : food) // cout << i << " "; // cout << endl; // cout << encode1(food) << endl; // return encode1(food); // } pair<int, int> addFood(int val, int newVal) { // cout << "val = " << val << endl; // cout << "newVal = " << newVal << endl; vector<int> oldFood = decoding[val]; // if((val < 4) && (val > 0)) // oldFood.push_back(val); // else if (val >= 4) // { // oldFood.push_back((val - 1) / 3); // if(val %3 == 0) // oldFood.push_back(3); // else // oldFood.push_back(val % 3); // } // for(int i = 0; i < 13; i++) // { // cout << "decoding[" << i << "] = ["; // vector<int> dec; // if((i < 4) && (i > 0)) // dec.push_back(i); // else if (i >= 4) // { // dec.push_back((i - 1) / 3); // if(i %3 == 0) // dec.push_back(3); // else // dec.push_back(i % 3); // } // for(int d : dec) // cout << d << ", "; // cout << "]" << endl; // } // cout << "food = " << endl; // for(int f : oldFood) // cout << f << " "; // cout << endl; // reverse(oldFood.begin(), oldFood.end()); oldFood.push_back(newVal); int count[4] = {}; for(int f : oldFood) { count[f]++; } int coal = 0; for(int i = 1; i < 4; i++) { if(count[i] > 0) coal++; } int enc = 0; if(oldFood.size() > 0) enc += oldFood.back(); if(oldFood.size() > 1) enc += 3 * oldFood[oldFood.size() - 2]; // assert(encode(oldFood) < 13); return make_pair(enc, coal); } int main() { decoding[0] = {}; decoding[1] = {1}; decoding[2] = {2}; decoding[3] = {3}; decoding[4] = {1, 1}; decoding[5] = {1, 2}; decoding[6] = {1, 3}; decoding[7] = {2, 1}; decoding[8] = {2, 2}; decoding[9] = {2, 3}; decoding[10] = {3, 1}; decoding[11] = {3, 2}; decoding[12] = {3, 3}; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; string food; cin >> food; const int numOps = 13; int states[2][numOps][numOps]; const int MININF = - 5 * N - (1e6); for(int x = 0; x < numOps; x++) { for(int y = 0; y < numOps; y++) { states[0][x][y] = MININF; states[0][x][y] = MININF; } } states[0][0][0] = 0; for(int i = 0; i < N; i++) { int num; if(food[i] == 'M') num = 1; else if (food[i] == 'B') num = 2; else if (food[i] == 'F') num = 3; // cout << "num = " << num << endl; int curId = i % 2, nextId = (i + 1) % 2; for(int x = 0; x < numOps; x++) { for(int y = 0; y < numOps; y++) states[nextId][x][y] = MININF; } for(int x = 0; x < numOps; x++) { for(int y = 0; y < numOps; y++) { pair<int, int> next1 = addFood(x, num); states[nextId][next1.first][y] = max(states[nextId][next1.first][y], states[curId][x][y] + next1.second); pair<int, int> next2 = addFood(y, num); states[nextId][x][next2.first] = max(states[nextId][x][next2.first], states[curId][x][y] + next2.second); } } } int ans = 0; for(int x = 0; x < numOps; x++) { for(int y = 0; y < numOps; y++) ans = max(ans, states[N%2][x][y]); } cout << ans; return 0; }

Compilation message (stderr)

miners.cpp: In function 'int encode(std::vector<int>&)':
miners.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
miners.cpp: In function 'int main()':
miners.cpp:178:42: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized]
  178 |     pair<int, int> next2 = addFood(y, num);
      |                                          ^
#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...