제출 #97765

#제출 시각아이디문제언어결과실행 시간메모리
97765Bodo171Growing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
3 ms384 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=405; int dp[2][nmax][nmax][3]; int ap[3],nr[3]; int p[3][nmax][3],a[3][nmax]; int n,i,j,k,use,oth,ch,nxt,ans; string s; int norm(char c) { if(c=='R') return 0; if(c=='G') return 1; return 2; } int actual_pos(int wh) { int ret=a[wh][ap[wh]]; for(int oth=0;oth<3;oth++) if(oth!=wh) ret+=max(0,ap[oth]-p[wh][ap[wh]][oth]); return ret; } void prp(int &a,int b) { a=min(a,b); } int main() { freopen("data.in","r",stdin); cin>>n; cin>>s;s=" "+s; for(i=1;i<=n;i++) a[norm(s[i])][++nr[norm(s[i])]]=i; for(i=0;i<3;i++) for(j=1;j<=nr[i];j++) for(oth=0;oth<3;oth++) { while(p[i][j][oth]<=nr[oth]&&a[oth][p[i][j][oth]]<a[i][j]) p[i][j][oth]++; p[i][j][oth]--; } for(i=0;i<2;i++) for(j=0;j<=n;j++) for(k=0;k<=n;k++) for(ch=0;ch<3;ch++) dp[i][j][k][ch]=(1<<30); for(i=0;i<3;i++) dp[0][0][0][i]=0; for(i=1;i<=n;i++) { use=1-use; for(j=0;j<=i;j++) for(k=0;k<=i-j;k++) for(ch=0;ch<3;ch++) { ap[0]=j;ap[1]=k;ap[2]=i-j-k; for(nxt=0;nxt<3;nxt++) if(nxt!=ch&&ap[nxt]<nr[nxt]) { ap[nxt]++; prp(dp[use][ap[0]][ap[1]][nxt],dp[1-use][j][k][ch]+actual_pos(nxt)-i); ap[nxt]--; } } for(j=0;j<=i;j++) for(k=0;k<=i-j;k++) for(ch=0;ch<3;ch++) { dp[1-use][j][k][ch]=(1<<30); } } ans=(1<<30); for(i=0;i<3;i++) ans=min(ans,dp[use][nr[0]][nr[1]][i]); if(ans==(1<<30)) ans=-1; cout<<ans; return 0; }

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

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