제출 #166953

#제출 시각아이디문제언어결과실행 시간메모리
166953DavidDamianMiners (IOI07_miners)C++11
100 / 100
828 ms119564 KiB
#include <bits/stdc++.h> using namespace std; ///Dynamic Programming ///Determine the maximum amount of coal we can get from sending food int n; int memo[100005][4][4][4][4]; string s; int convert(char c) ///Converts a character into a code { if(c=='M') return 1; if(c=='F') return 2; if(c=='B') return 3; } int production(vector<int>& prev,int mine,int next) ///Determines how many coal are produced with a given shipments { int a,b; if(mine==1) a=0,b=2; else a=2,b=4; short used[5]; memset(used,0,sizeof(used)); int total=0; for(int i=a;i<b;i++){ if(prev[i]==0) continue; int food=prev[i]; if(!used[food]){ used[food]=1; total++; } } if(!used[next]) total++; return total; } int coal(int i,vector<int> prev) { if(i==n) return 0; int maximum=0; vector<int> next=prev; int food=convert(s[i]); if(memo[i][ prev[0] ][ prev[1] ][ prev[2] ][ prev[3] ]==0){ //If there are -1 does not store the answer int k=production(prev,1,food); //Obtains the amount of coal if the food was shipped to mine 1 next[0]=prev[1]; next[1]=food; maximum=max(maximum,coal(i+1,next)+k); //And we get the answer of that mine next[0]=prev[0]; next[1]=prev[1]; next[2]=prev[3]; next[3]=food; k=production(prev,2,food); maximum=max(maximum,coal(i+1,next)+k); //Obtains the amount of coal if the food was shipped to mine 2 memo[i][ prev[0] ][ prev[1] ][ prev[2] ][ prev[3] ]=maximum; } return memo[i][ prev[0] ][ prev[1] ][ prev[2] ][ prev[3] ]; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; cin>>s; vector<int> A; int food=convert(s[0]); A.push_back(0); A.push_back(food); A.push_back(0); A.push_back(0); //We always send food 1 to mine 1 because we obtain the same results sending it to both mines int total=coal(1,A)+1; //Because that we add one to the answer cout<<total<<'\n'; return 0; }

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

miners.cpp: In function 'int convert(char)':
miners.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...