제출 #1059887

#제출 시각아이디문제언어결과실행 시간메모리
1059887ZicrusWiring (IOI17_wiring)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;

typedef long long ll;

ll min_total_length(vector<int> r, vector<int> b) {
	vector<vector<int>> rb = {r, b};
    vector<pair<ll, pair<ll, ll>>> pos; // pos, {type, id in type}
    for (int i = 0; i < r.size(); i++) pos.push_back({r[i], {0, i}});
    for (int i = 0; i < b.size(); i++) pos.push_back({b[i], {1, i}});
    sort(pos.begin(), pos.end());
    ll n = pos.size();

    vector<int> last(2, -1);
    vector<int> nxt(2, 1);
    vector<bool> vst(n);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (vst[i]) continue;

        ll otherT = pos[i].second.first ^ 1;
        while (nxt[otherT] < n && (vst[nxt[otherT]] || pos[nxt[otherT]].second.first != otherT)) nxt[otherT]++;
        if (nxt[otherT] >= n) {
            res += pos[i].first - last[otherT];
        }
        else {
            res += pos[nxt[otherT]].first - pos[i].first;
            vst[nxt[otherT]] = true;
        }

        vst[i] = true;
        last[pos[i].second.first] = pos[i].first;
    }

    return res;
}

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

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