제출 #1062750

#제출 시각아이디문제언어결과실행 시간메모리
1062750mindiyak전선 연결 (IOI17_wiring)C++14
0 / 100
1057 ms16176 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> #include <limits> 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<vector<ll>> vvl; 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) { int n = r.size(), m = b.size(); vector<pair<int,pi>> arr; FOR(i,0,n)arr.pb({r[i],{0,i}}); FOR(i,0,m)arr.pb({b[i],{1,i}}); vector<priority_queue<pi>> con(n+m); sort(arr.begin(),arr.end()); int lastr = -1,lastb = -1; FOR(i,0,n+m){ if(lastr != -1 && lastb != -1)break; if(lastr == -1 && arr[i].S.F == 0)lastr = i; if(lastb == -1 && arr[i].S.F == 0)lastb = i; } ll ans = 0; FOR(i,0,arr.size()){ pi edge = arr[i].S; cerr << endl << arr[i].F << " " << (edge.F ? "blue" : "red") << " " << edge.S << " | " << con[i].size() << " - " << endl; if(con[i].size()>0)continue; if(edge.F == 1){ int dis = abs(arr[lastr].F-arr[i].F); ans += dis; if(con[lastr].size() > 0){ pi node = con[lastr].top(); if(con[node.S].size() > 1){ cerr << "remove " << node.F << " | " << arr[lastr].F << " " << node.S << endl; con[lastr].pop(); ans -= node.F; } } con[lastr].push({dis,i}); con[i].push({dis,lastr}); cerr << "connect " << dis << " | " << arr[i].F << " & " << arr[lastr].F << endl; lastb = i; }else{ int dis = abs(arr[lastb].F-arr[i].F);; ans += dis; if(con[lastb].size() > 0){ pi node = con[lastb].top(); if(con[node.S].size() > 1){ cerr << "remove " << arr[lastb].F << " " << node.S << endl; con[lastb].pop(); ans -= node.F; } } con[lastb].push({dis,i}); con[i].push({dis,lastb}); cerr << "connect " << dis << " | " << arr[i].F << " & " << arr[lastb].F << endl; lastr = i; } } return ans; }

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

wiring.cpp: In function 'long long int min_total_length(vi, vi)':
wiring.cpp:24:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 | #define FOR(i, a, b) for (int i = a; i < (b); i++)
      |                                        ^
wiring.cpp:62:2: note: in expansion of macro 'FOR'
   62 |  FOR(i,0,arr.size()){
      |  ^~~
#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...