제출 #1237180

#제출 시각아이디문제언어결과실행 시간메모리
1237180antromancapGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++20
100 / 100
340 ms774688 KiB
#include <bits/stdc++.h> using namespace std; template <class T> bool mini(T &x, const T &y) { return y < x ? x = y, 1 : 0; } template <class T> bool maxi(T &x, const T &y) { return y > x ? x = y, 1 : 0; } const int N = 404; int sz, n, m, p, dp[N][N][N][3], pos[N][3], pref[N][3]; char a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); scanf("%d%s", &sz, a + 1); for (int i = 1; i <= sz; i++) { copy(pref[i - 1], pref[i - 1] + 3, pref[i]); if (a[i] == 'R') pos[++n][0] = i, pref[i][0]++; if (a[i] == 'G') pos[++m][1] = i, pref[i][1]++; if (a[i] == 'Y') pos[++p][2] = i, pref[i][2]++; } memset(dp, 0x3f, sizeof dp); dp[0][0][0][0] = 0; dp[0][0][0][1] = 0; dp[0][0][0][2] = 0; for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) for (int k = 0; k <= p; k++) for (int l = 0; l < 3; l++) { int &res = dp[i][j][k][l]; if (res > 1e9) continue; if (l != 0) mini(dp[i + 1][j][k][0], res + max(0, pref[pos[i + 1][0]][1] - j) + max(0, pref[pos[i + 1][0]][2] - k)); if (l != 1) mini(dp[i][j + 1][k][1], res + max(0, pref[pos[j + 1][1]][0] - i) + max(0, pref[pos[j + 1][1]][2] - k)); if (l != 2) mini(dp[i][j][k + 1][2], res + max(0, pref[pos[k + 1][2]][0] - i) + max(0, pref[pos[k + 1][2]][1] - j)); } int res = *min_element(dp[n][m][p], dp[n][m][p] + 3); cout << (res > 1e9 ? -1 : res); }

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d%s", &sz, a + 1);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...