이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// MinersIOI2007.cpp
//
//
// Created by Matjaz Leonardis on 04/12/2023.
//
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
using namespace std;
// Trying all the different Miners solutions
int N;
string food;
vector<int> f;
int dp[100005][16][16];
int product(int state, int shipment){
vector<int> shipments;
shipments.push_back(shipment);
shipments.push_back(state % 4);
shipments.push_back(state / 4);
bool one = false, two= false, three=false;
for (int i=0;i<shipments.size();i++){
if (shipments[i] == 1) one = true;
if (shipments[i] == 2) two = true;
if (shipments[i] == 3) three = true;
}
return one + two + three;
}
int coal(int x, int mine1, int mine2){
if (x >= N) return 0;
if (dp[x][mine1][mine2] != -1) return dp[x][mine1][mine2];
int tomine1 = product(mine1, f[x]) + coal(x + 1, mine1 / 4 + 4 * f[x], mine2);
int tomine2 = product(mine2, f[x]) + coal(x + 1, mine1, mine2 / 4 + 4 * f[x]);
return dp[x][mine1][mine2] = max(tomine1, tomine2);
}
int main(){
memset(dp, -1, sizeof(dp));
cin >> N;
cin >> food;
f.assign(N, 0);
for (int i=0;i<N;i++){
if (food[i] == 'B') f[i] = 1;
if (food[i] == 'M') f[i] = 2;
if (food[i] == 'F') f[i] = 3;
}
cout << coal(0,0,0) << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int product(int, int)':
miners.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i=0;i<shipments.size();i++){
| ~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |