제출 #295195

#제출 시각아이디문제언어결과실행 시간메모리
295195BruteforcemanSky Walking (IOI19_walk)C++17
33 / 100
1210 ms119836 KiB
#include "bits/stdc++.h" #include "walk.h" using namespace std; const int maxNode = 2e6 + 10; const int maxn = 1e5 + 10; const long long inf = 1e16; int node = 0; vector <pair <int, int>> g[maxNode]; vector <int> start[maxn], fin[maxn]; vector <pair <int, int>> bridge[maxn]; vector <pair <int, int>> line[maxn]; struct vertex { int node; long long dist; vertex() {} vertex(int node, long long dist) : node(node), dist(dist) {} bool operator < (vertex v) const { return dist > v.dist; } }; void addEdge(int i, int j, int cost) { // cout << i << " " << j << " " << cost << endl; g[i].emplace_back(j, cost); g[j].emplace_back(i, cost); } long long shortest_path(int src, int des) { priority_queue <vertex> Q; vector <long long> dist (node, inf); Q.emplace(src, 0); dist[src] = 0; while(not Q.empty()) { auto x = Q.top(); Q.pop(); if(x.dist != dist[x.node]) continue; for(auto i : g[x.node]) { if(i.second + x.dist < dist[i.first]) { dist[i.first] = i.second + x.dist; Q.emplace(i.first, dist[i.first]); } } } return dist[des]; } long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int from, int to) { for(int i = 0; i < l.size(); i++) { start[l[i]].push_back(i); fin[r[i]].push_back(i); } set <pair <int, int>> cont; int src = 0, des = 0; for(int i = 0; i < x.size(); i++) { for(int j : start[i]) { cont.insert(make_pair(y[j], j)); } vector <pair <int, int>> can; if(from == i) { can.push_back(make_pair(0, -1)); } if(to == i) { can.push_back(make_pair(0, -1)); } for(int j : start[i]) { auto it = cont.find(make_pair(y[j], j)); can.emplace_back(y[j], j); if(it != cont.begin()) { can.push_back(*prev(it)); } if(next(it) != cont.end() && next(it) -> first <= h[i]) { can.push_back(*next(it)); } } for(int j : fin[i]) { auto it = cont.find(make_pair(y[j], j)); can.emplace_back(y[j], j); if(it != cont.begin()) { can.push_back(*prev(it)); } if(next(it) != cont.end() && next(it) -> first <= h[i]) { can.push_back(*next(it)); } } line[i] = can; for(int j : fin[i]) { cont.erase(make_pair(y[j], j)); } } for(int i = 0; i < x.size(); i++) { for(int j = 0; j < line[i].size(); j++) { if(line[i][j].second == -1) { if(i == from) src = node; else des = node; } else { bridge[line[i][j].second].emplace_back(x[i], node); } line[i][j].second = node++; } } for(int i = 0; i < x.size(); i++) { sort(line[i].begin(), line[i].end()); for(int j = 1; j < line[i].size(); j++) { addEdge(line[i][j - 1].second, line[i][j].second, line[i][j].first - line[i][j - 1].first); } } for(int i = 0; i < l.size(); i++) { sort(bridge[i].begin(), bridge[i].end()); for(int j = 1; j < bridge[i].size(); j++) { addEdge(bridge[i][j - 1].second, bridge[i][j].second, bridge[i][j].first - bridge[i][j - 1].first); } } auto ans = shortest_path(src, des); return ans >= inf ? -1 : ans; }

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

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int i = 0; i < l.size(); i++) {
      |                  ~~^~~~~~~~~~
walk.cpp:54:20: 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 < x.size(); i++) {
      |                  ~~^~~~~~~~~~
walk.cpp:90:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |   for(int i = 0; i < x.size(); i++) {
      |                  ~~^~~~~~~~~~
walk.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int j = 0; j < line[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~
walk.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |   for(int i = 0; i < x.size(); i++) {
      |                  ~~^~~~~~~~~~
walk.cpp:103:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |     for(int j = 1; j < line[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~
walk.cpp:108:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |   for(int i = 0; i < l.size(); i++) {
      |                  ~~^~~~~~~~~~
walk.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int j = 1; j < bridge[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~~~
#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...