Submission #444188

#TimeUsernameProblemLanguageResultExecution timeMemory
444188nonsensenonsense1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
15 / 100
348 ms757504 KiB
#include <cstdio> #include <algorithm> #include <cstring> const int INF = 0x3f3f3f3f; const int N = 401; int n, amt[3], pos[3][N], d[N][N][N][3]; char s[N]; int f(int last) { int &cur = d[amt[0]][amt[1]][amt[2]][last]; if (cur == -1) { cur = INF; if (!(amt[0] + amt[1] + amt[2])) cur = 0; else for (int i = 0; i < 3; ++i) if (i != last && amt[i]) { --amt[i]; cur = std::min(cur, f(i) + abs(amt[0] + amt[1] + amt[2] - pos[i][amt[i]])); ++amt[i]; } } return cur; } int main() { memset(***d, -1, N * N * N * 3 << 2); scanf("%d%s", &n, s); for (int i = 0; i < n; ++i) { int cur; if (s[i] == 'R') cur = 0; else if (s[i] == 'G') cur = 1; else cur = 2; pos[cur][amt[cur]++] = i; } int ans = INF; for (int i = 0; i < 3; ++i) ans = std::min(ans, f(i)); if (ans == INF) printf("-1\n"); else printf("%d\n", ans >> 1); return 0; }

Compilation message (stderr)

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