제출 #1317797

#제출 시각아이디문제언어결과실행 시간메모리
1317797JuanJLGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++20
75 / 100
725 ms323052 KiB
#include <bits/stdc++.h> #define fst first #define snd second #define pb push_back #define forn(i,a,b) for(int i = a; i<b; i++) #define SZ(x) (int)x.size() #define ALL(x) x.begin(),x.end() #define mset(a,v) memset(a,v,sizeof(a)) #define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; typedef long long ll; string opc = "RGY"; ll dp[5][202][202][202]; ll n; string s; vector<vector<ll>> pos(3); map<char,ll> ri; ll select(ll k , ll R, ll G, ll Y){ if(k==0) return R; if(k==1) return G; if(k==2) return Y; } ll f(ll ant, ll R, ll G, ll Y){ ll &res = dp[ant][R][G][Y]; if(res!=-1) return res; ll x = R+G+Y; if(x==n) return 0; res = 10000000000; forn(k,0,3){ if(k==ant) continue; ll rgy = select(k,R,G,Y); if(rgy==SZ(pos[k])) continue; ll cost = 0; ll j = pos[k][rgy]; forn(h,0,3){ ll mrgy = select(h,R,G,Y); cost += max((ll)0,(lower_bound(ALL(pos[h]),j)-pos[h].begin()) - mrgy); } ll nR = R; if(k==0) nR++; ll nG = G; if(k==1) nG++; ll nY = Y; if(k==2) nY++; res=min(res, f(k,nR,nG,nY)+cost); } //cout<<x<<" "<<R<<" "<<G<<" "<<Y<<"-------> "<<res<<'\n'; return res; } int main(){ FIN; cin>>n; cin>>s; ri['R']=0; ri['G']=1; ri['Y']=2; forn(i,0,n) pos[ri[s[i]]].pb(i); if(SZ(pos[0])>=202 || SZ(pos[1])>=202 || SZ(pos[2])>=202){ cout<<"-1\n"; exit(0); } mset(dp,-1); ll res=f(4,0,0,0); if(res>1000000000) cout<<"-1"<<'\n'; else cout<<res<<'\n'; return 0; }

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

joi2019_ho_t3.cpp: In function 'll select(ll, ll, ll, ll)':
joi2019_ho_t3.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...