제출 #50970

#제출 시각아이디문제언어결과실행 시간메모리
50970model_code오렌지 출하 (JOI16_ho_t1)C++17
100 / 100
152 ms3124 KiB
#include <cstdio> #include <vector> #include <algorithm> typedef long long int64; const int64 INF = 1e18; int64 dfs(const int pos, const int M, const int K, const std::vector<int>& oranges, std::vector<int64>& memo) { const int N = (int)oranges.size(); if(pos >= N) return 0; if(memo[pos] < INF) return memo[pos]; int64& ans = memo[pos]; ans = INF; int64 max_orange = oranges[pos]; int64 min_orange = oranges[pos]; for(int right = pos; right < std::min(N, pos + M); ++right) { const int64 o = oranges[right]; max_orange = std::max(max_orange, o); min_orange = std::min(min_orange, o); const int64 diff = max_orange - min_orange; const int64 cost = K + (right - pos + 1) * diff; const int64 total = cost + dfs(right + 1, M, K, oranges, memo); ans = std::min(ans, total); } return ans; } int main() { int N, M, K; std::vector<int> oranges; scanf("%d%d%d", &N, &M, &K); oranges.resize(N); for(auto& o : oranges) { int t; scanf("%d", &t); o = t; } std::vector<int64> memo; memo.resize(N, INF); int64 ans = dfs(0, M, K, oranges, memo); printf("%lld\n", ans); return 0; }

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

2016_ho_t1.cpp: In function 'int main()':
2016_ho_t1.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &M, &K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2016_ho_t1.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &t);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...