Submission #98325

#TimeUsernameProblemLanguageResultExecution timeMemory
98325rosiMiners (IOI07_miners)C++14
100 / 100
32 ms896 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005; const int inf = -1; int dp[2][4][4][4]; int shipment[MAX_N]; char s[MAX_N]; int n; int goat(int a, int b, int c) { int ret = 0; if (a == 1 || b == 1 || c == 1) { ret++; } if (a == 2 || b == 2 || c == 2) { ret++; } if (a == 3 || b == 3 || c == 3) { ret++; } return ret; } void Max(int &a, int b) { a = max(a, b); } void dynamicProgramming() { for (int a = 0; a <= 3; a++) { for (int b = 0; b <= 3; b++) { for (int c = 0; c <= 3; c++) { dp[0][a][b][c] = inf; } } } dp[0][0][0][0] = 0; int res = 0; for (int i = 0; i <= n; i++) { int cur = i & 1; int nxt = !cur; for (int a = 0; a <= 3; a++) { for (int b = 0; b <= 3; b++) { for (int c = 0; c <= 3; c++) { dp[nxt][a][b][c] = inf; } } } for (int a = 0; a <= 3; a++) { for (int b = 0; b <= 3; b++) { for (int c = 0; c <= 3; c++) { if (dp[cur][a][b][c] == inf) { continue; } int val = dp[cur][a][b][c]; res = max(res, val); Max(dp[nxt][shipment[i]][b][c], val + goat(a, shipment[i], shipment[i + 1])); Max(dp[nxt][c][a][shipment[i]], val + goat(b, c, shipment[i + 1])); } } } } printf("%d", res); } int main () { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d", &n); scanf("%s", s); for (int i = 1; i <= n; i++) { if (s[i - 1] == 'M') { shipment[i] = 1; } else if (s[i - 1] == 'F') { shipment[i] = 2; } else { shipment[i] = 3; } } dynamicProgramming(); return 0; }

Compilation message (stderr)

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