Submission #942478

#TimeUsernameProblemLanguageResultExecution timeMemory
942478artixkrishnaMiners (IOI07_miners)C++14
100 / 100
19 ms620 KiB
#include <algorithm> #include <cstdio> #include <cstdlib> using namespace std; const int MAX = 100005; int n; char s[MAX + 1]; int dp[2][4][4][4]; void read_input() { scanf("%d\n", &n); fgets(s, MAX + 1, stdin); for (int i = 0; i < n; i++) if (s[i] == 'F') s[i] = 1; else if (s[i] == 'M') s[i] = 2; else s[i] = 3; } inline int ore(int a, int b, int c) { int sol = 0; if (a == 1 || b == 1 || c == 1) sol++; if (a == 2 || b == 2 || c == 2) sol++; if (a == 3 || b == 3 || c == 3) sol++; return sol; } int main() { read_input(); int now = 0, prev = 1; for (int k = n - 1; k >= 0; --k) { for (int a = 0; a <= 3; ++a) { for (int b = 0; b <= 3; ++b) { for (int c = 0; c <= 3; ++c) { int left = ore(s[k], s[k - 1], a) + dp[prev][s[k - 1]][b][c]; int right = ore(s[k], b, c) + dp[prev][b][s[k - 1]][a]; dp[now][a][b][c] = max(left, right); } } } swap(now, prev); } printf("%d\n", dp[prev][0][0][0]); return 0; }

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:44:63: warning: array subscript has type 'char' [-Wchar-subscripts]
   44 |           int left = ore(s[k], s[k - 1], a) + dp[prev][s[k - 1]][b][c];
      |                                                        ~~~~~~~^
miners.cpp:45:60: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |           int right = ore(s[k], b, c) + dp[prev][b][s[k - 1]][a];
      |                                                     ~~~~~~~^
miners.cpp: In function 'void read_input()':
miners.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d\n", &n);
      |   ~~~~~^~~~~~~~~~~~
miners.cpp:15:8: warning: ignoring return value of 'char* fgets(char*, int, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fgets(s, MAX + 1, stdin);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
#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...