제출 #166954

#제출 시각아이디문제언어결과실행 시간메모리
166954DavidDamianMiners (IOI07_miners)C++11
100 / 100
473 ms632 KiB
#include <bits/stdc++.h> using namespace std; ///Dynamic Programming ///Bottom-Up ///Memory Saving ///Determine the maximum amount of coal we can get from sending food int n; int memo[2][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; } vector<int> Prev; int production(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 main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; cin>>s; Prev.resize(4); for(int i=n-1;i>=0;i--){ int food=convert(s[i]); for(int k1=0;k1<4;k1++){ //Tries all the possible combinations of food history Prev[0]=k1; for(int k2=0;k2<4;k2++){ Prev[1]=k2; for(int k3=0;k3<4;k3++){ Prev[2]=k3; for(int k4=0;k4<4;k4++){ Prev[3]=k4; int maximum=0; int coal=production(1,food); //Send the food to mine 1 maximum=max(maximum,memo[(i+1)%2][k2][food][k3][k4]+coal); coal=production(2,food); //Send the food to mine 2 maximum=max(maximum,memo[(i+1)%2][k1][k2][k4][food]+coal); memo[i%2][k1][k2][k3][k4]=maximum; } } } } } int total=max(memo[0][0][0][0][0],memo[1][0][0][0][0]); cout<<total<<'\n'; return 0; }

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

miners.cpp: In function 'int convert(char)':
miners.cpp:15: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...