Submission #330639

#TimeUsernameProblemLanguageResultExecution timeMemory
330639mickytanawinMiners (IOI07_miners)C++14
100 / 100
294 ms876 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<char, int> pci; const int N = 1e5; int food[N + 1], dp[2][4][4][4][4]; char str[N + 1]; map<char, int> conv = {pci('M', 1), pci('F', 2), pci('B', 3)}; int nFood; int mineCoal(int a, int b, int c){ int ans = 0; if(a == 1 || b == 1 || c == 1){ ++ans; } if(a == 2 || b == 2 || c == 2){ ++ans; } if(a == 3 || b == 3 || c == 3){ ++ans; } return ans; } int dpTopDown(int i, int x1, int x2, int y1, int y2){ if(i == nFood + 1){ return 0; } if(dp[i][x1][x2][y1][y2] > 0){ return dp[i][x1][x2][y1][y2]; } return dp[i][x1][x2][y1][y2] = max(mineCoal(x1, x2, food[i]) + dpTopDown(i + 1, food[i], x1, y1, y2), mineCoal(y1, y2, food[i]) + dpTopDown(i + 1, x1, x2, food[i], y1)); } int main(){ scanf("%d", &nFood); scanf(" %s", str); for(int i = 1; i <= nFood; ++i){ food[i] = conv[str[i - 1]]; } for(int i = nFood + 1; i >= 1; --i){ for(int x1 = 0; x1 <= 3; ++x1){ for(int x2 = 0; x2 <= 3; ++x2){ for(int y1 = 0; y1 <= 3; ++y1){ for(int y2 = 0; y2 <= 3; ++y2){ int curr = i % 2; int next = curr ^ 1; if(i == nFood + 1){ dp[curr][x1][x2][y1][y2] = 0; } else { dp[curr][x1][x2][y1][y2] = max(mineCoal(x1, x2, food[i]) + dp[next][food[i]][x1][y1][y2], mineCoal(y1, y2, food[i]) + dp[next][x1][x2][food[i]][y1]); } } } } } } cout << dp[1][0][0][0][0]; return 0; }

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("%d", &nFood);
      |     ~~~~~^~~~~~~~~~~~~~
miners.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |     scanf(" %s", str);
      |     ~~~~~^~~~~~~~~~~~
#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...