Submission #542081

#TimeUsernameProblemLanguageResultExecution timeMemory
542081MdominykasMiners (IOI07_miners)C++14
84 / 100
1589 ms468 KiB
/*input 16 MMBMBBBBMMMMMBMB */ #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> decode(int val) { vector<int> ans; ans.push_back(val % 4); val /= 4; ans.push_back(val % 4); reverse(ans.begin(), ans.end()); for(int i = 0; i < ans.size(); i++) { if(ans[i] == 0) { swap(ans[i], ans.back()); ans.pop_back(); i--; } } return ans; } 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 4 * food[0] + food[1]; throw "too much food"; } int coal(vector<int> &food) { int count[4] = {}; for(int f : food) count[f]++; int ans = 0; for(int i = 1; i < 4; i++) { if(count[i] > 0) ans++; } return ans; } pair<int, int> addFood(int val, int newVal) { vector<int> oldFood = decode(val); oldFood.push_back(newVal); int res = coal(oldFood); if(oldFood.size() > 2) { reverse(oldFood.begin(), oldFood.end()); oldFood.pop_back(); reverse(oldFood.begin(), oldFood.end()); } return make_pair(encode(oldFood), res); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; string food; cin >> food; const int numOps = 16; 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 'std::vector<int> decode(int)':
miners.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
miners.cpp: In function 'int main()':
miners.cpp:130:42: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized]
  130 |     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...