제출 #552540

#제출 시각아이디문제언어결과실행 시간메모리
552540timreizin전선 연결 (IOI17_wiring)C++17
7 / 100
136 ms262144 KiB
#include "wiring.h"
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

ll min_total_length(vector<int> r, vector<int> b)
{
    vector<vector<ll>> dp(r.size(), vector<ll>(b.size()));
    for (int i = 0; i < b.size(); ++i)
    {
        dp[0][i] = abs(r[0] - b[i]);
        if (i != 0) dp[0][i] += dp[0][i - 1];
    }
    for (int i = 1; i < r.size(); ++i)
    {
        for (int j = 0; j < b.size(); ++j)
        {
            dp[i][j] = dp[i - 1][j] + abs(r[i] - b[j]);
            if (j != 0)
            {
                dp[i][j] = min({dp[i][j], dp[i][j - 1] + abs(r[i] - b[j]),
                                dp[i - 1][j - 1] + abs(r[i] - b[j])});
            }
            /*ll sum = 0;
            for (int k = j - 1; k >= 0; --k)
            {
                sum += abs(r[i] - b[k + 1]);
                dp[i][j] = min(dp[i][j], dp[i - 1][k] + sum);
            }*/
        }
    }
	return dp.back().back();
}

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

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < b.size(); ++i)
      |                     ~~^~~~~~~~~~
wiring.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 1; i < r.size(); ++i)
      |                     ~~^~~~~~~~~~
wiring.cpp:20:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int j = 0; j < b.size(); ++j)
      |                         ~~^~~~~~~~~~
#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...