제출 #1035750

#제출 시각아이디문제언어결과실행 시간메모리
1035750mindiyak전선 연결 (IOI17_wiring)C++14
0 / 100
0 ms348 KiB
#include "wiring.h" #pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = a; i < (b); i++) // #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; long long min_total_length(vi r, vi b) { priority_queue <pair<int,pi>> pq; int n = r.size(), m = b.size(); int posr = 0,posb = 0; vi cnt_r(n,0), cnt_b(m,0); while(posr < n && posb < m){ int p = min(posr,n-1), q = min(posb,m-1); cnt_r[p]++; cnt_b[q]++; pq.push({abs(r[p]-b[q]),{p,q}}); if(r[p] < b[q] && posr < n-1){ posr++; }else{ posb++; } } ll ans = 0; while(!pq.empty()){ pair<int,pi> edge = pq.top();pq.pop(); // cout << edge.F << " " << r[edge.S.F] << " " << b[edge.S.S] << " "; if(cnt_r[edge.S.F] > 1 && cnt_b[edge.S.S] > 1){ cnt_r[edge.S.F]--; cnt_b[edge.S.S]--; // cout << "-" << endl; }else{ ans += edge.F; // cout << "+" << endl; } } return ans; }
#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...