제출 #340144

#제출 시각아이디문제언어결과실행 시간메모리
340144shrek12357전선 연결 (IOI17_wiring)C++14
20 / 100
39 ms7132 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
//#include "molecules.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
using namespace std;
ll dp[200002];
ll dp1[202][202];
ll inf = 1e9;
ll fun(vector <int> x, vector <int> y) {
    ll ans = 0;
    if (x.size() == 0 || y.size() == 0)
        return inf;
    for (int i = 0; i <= x.size(); i++) {
        for (int j = 0; j <= y.size(); j++) {
            dp1[i][j] = inf;
        }
    }
    dp1[0][0] = 0;
    for (int i = 0; i < x.size(); i++) {
        for (int j = 0; j < y.size(); j++) {
            dp1[i + 1][j + 1] = min(dp1[i][j], min(dp1[i][j + 1], dp1[i + 1][j])) + +abs(x[i] - y[j]);
        }
    }
    return dp1[x.size()][y.size()];
}

ll min_total_length(std::vector<int> r, std::vector<int> b) {
    vector < pair <int, int> > pr;
    sort(r.begin(), r.end());
    sort(b.begin(), b.end());

    int n = r.size();
    int m = b.size();
    for (int i = 0; i < n; i++) {
        pr.push_back(make_pair(r[i], 0));
    }
    for (int i = 0; i < m; i++) {
        pr.push_back(make_pair(b[i], 1));
    }
    if (r.back() < b[0]) {
        ll sum = 0;
        for (int i = 0; i < r.size(); i++)
            sum += (r.back() - r[i]);
        for (int i = 0; i < b.size(); i++)
            sum += (b[i] - b[0]);
        return sum + max(r.size(), b.size()) * 1ll * (b[0] - r.back());
    }
    if (n > 201 || m > 201) {
        for (int i = 0; i < n + m; i++) {
            dp[i] = inf;
            for (int j = i - 1; j >= 0 && i - j > 14; j--) {
                vector <int> r1, b1;
                for (int k = j; k <= j; k++) {
                    if (pr[k].second == 0)
                        r1.push_back(pr[k].first);
                    else
                        b1.push_back(pr[k].first);
                }
                if (j == 0)
                    dp[i] = min(dp[i], fun(r1, b1));
                else
                    dp[i] = min(dp[i], dp[j - 1] + fun(r1, b1));
            }
        }
        return dp[n + m - 1];
    }

    return fun(r, b);
}

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

wiring.cpp: In function 'long long int fun(std::vector<int>, std::vector<int>)':
wiring.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i <= x.size(); i++) {
      |                     ~~^~~~~~~~~~~
wiring.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j = 0; j <= y.size(); j++) {
      |                         ~~^~~~~~~~~~~
wiring.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < x.size(); i++) {
      |                     ~~^~~~~~~~~~
wiring.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j = 0; j < y.size(); j++) {
      |                         ~~^~~~~~~~~~
wiring.cpp:22:8: warning: unused variable 'ans' [-Wunused-variable]
   22 |     ll ans = 0;
      |        ^~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < r.size(); i++)
      |                         ~~^~~~~~~~~~
wiring.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = 0; i < b.size(); i++)
      |                         ~~^~~~~~~~~~
#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...