Submission #878808

# Submission time Handle Problem Language Result Execution time Memory
878808 2023-11-25T08:56:06 Z junha1282 Wiring (IOI17_wiring) C++14
Compilation error
0 ms 0 KB
#include "wiring.h"
#include <bits/stdc++.h>

using namespace std;

long long min_total_length(std::vector<int> s, std::vector<int> t) {
    int n, m, si = 0, ti = 0;
    cin>>n>>m;
    vector<long long> s(n), t(m), ss(n+m+1), st(n+m+1), dp(n+m+1), c(2*n+2*m+2);
    vector<pair<long long, int>> v;
    v.push_back({-1, 0});
    for (int i = 0; i < n; i++) {
        cin>>s[i];
        v.push_back({s[i], 0});
    }
    for (int i = 0; i < m; i++) {
        cin>>t[i];
        v.push_back({t[i], 1});
    }
    sort(v.begin(), v.end());
    int x = n+m;
    for (int i = 1; i <= n+m; i++) {
        si = lower_bound(s.begin(), s.end(), v[i].first) - s.begin();
        if(si == s.size()) si--;
        if(si > 0 && s[si] > v[i].first) si--;
        ti = lower_bound(t.begin(), t.end(), v[i].first) - t.begin();
        if(ti == t.size()) ti--;
        if(ti > 0 && t[ti] > v[i].first) ti--;
        ss[i] = ss[i-1];
        st[i] = st[i-1];
        long long tmp = 0;
        if(v[i].second == 1){
            if(si < n-1) {
                tmp = min(abs(s[si] - v[i].first), abs(s[si+1] - v[i].first));
            } else {
                tmp = abs(s[si] - v[i].first);
            }
            x++;
            ss[i] += v[i].first;
        } else {
            if(ti < m-1) {
                tmp = min(abs(t[ti] - v[i].first), abs(t[ti+1] - v[i].first));
            } else {
                tmp = abs(t[ti] - v[i].first);
            }
            x--;
            st[i] += v[i].first;
        }
        if(c[x] != 0){
            dp[i] = min(dp[i-1] + tmp, dp[c[x]] + abs(ss[i] - ss[c[x]] + st[c[x]] - st[i]));
        } else {
            dp[i] = dp[i-1] + tmp;
        }
        c[x] = i;
    }
    return dp[n+m];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:9:23: error: declaration of 'std::vector<long long int> s' shadows a parameter
    9 |     vector<long long> s(n), t(m), ss(n+m+1), st(n+m+1), dp(n+m+1), c(2*n+2*m+2);
      |                       ^
wiring.cpp:6:45: note: 'std::vector<int> s' previously declared here
    6 | long long min_total_length(std::vector<int> s, std::vector<int> t) {
      |                            ~~~~~~~~~~~~~~~~~^
wiring.cpp:9:29: error: declaration of 'std::vector<long long int> t' shadows a parameter
    9 |     vector<long long> s(n), t(m), ss(n+m+1), st(n+m+1), dp(n+m+1), c(2*n+2*m+2);
      |                             ^
wiring.cpp:6:65: note: 'std::vector<int> t' previously declared here
    6 | long long min_total_length(std::vector<int> s, std::vector<int> t) {
      |                                                ~~~~~~~~~~~~~~~~~^
wiring.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if(si == s.size()) si--;
      |            ~~~^~~~~~~~~~~
wiring.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if(ti == t.size()) ti--;
      |            ~~~^~~~~~~~~~~