제출 #171299

#제출 시각아이디문제언어결과실행 시간메모리
171299dennisstarGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++11
100 / 100
222 ms196768 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ryan bear #define now mem[co][r][g][y] #define all(V) ((V).begin()), ((V).end()) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; typedef vector<int> vim; typedef vector<ll> vlm; int n, ar[410], mem[3][410][410][410], cnt[3][410]; char s[410]; vim c[3]; int f(int co, int r, int g, int y) { if (!(r+g+y)) return 0; if (now!=-1) return now; now=(1<<30); if (r&&co==0) now = min( now , min(f(1, r-1, g, y), f(2, r-1, g, y))+abs(g-cnt[1][c[0][r-1]])+abs(y-cnt[2][c[0][r-1]])); if (g&&co==1) now = min( now , min(f(0, r, g-1, y), f(2, r, g-1, y))+abs(r-cnt[0][c[1][g-1]])+abs(y-cnt[2][c[1][g-1]])); if (y&&co==2) now = min( now , min(f(0, r, g, y-1), f(1, r, g, y-1))+abs(r-cnt[0][c[2][y-1]])+abs(g-cnt[1][c[2][y-1]])); return now; } int main() { scanf("%d %s", &n, s); for (int i=1; i<=n; i++) ar[i]=(s[i-1]=='R'?0:(s[i-1]=='G'?1:2)); for (int i=1; i<=n; i++) c[ar[i]].push_back(i); for (int i=1; i<=n; i++) { for (int j=0; j<3; j++) cnt[j][i]=cnt[j][i-1]; cnt[ar[i]][i]++; } for (int i=0; i<3; i++) for (int j=0; j<=cnt[0][n]; j++) for (int k=0; k<=cnt[1][n]; k++) for (int l=0; l<=cnt[2][n]; l++) mem[i][j][k][l]=-1; int ans=(1<<30); for (int i=0; i<3; i++) if (c[i].size()) ans=min(ans, f(i, cnt[0][n], cnt[1][n], cnt[2][n])); if (ans==(1<<30)) {puts("-1"); return 0;} printf("%d\n", ans/2); return 0; }

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

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