Submission #59890

#TimeUsernameProblemLanguageResultExecution timeMemory
59890Eae02New Home (APIO18_new_home)C++14
0 / 100
5092 ms13804 KiB
#include <bits/stdc++.h> #define ALL(x) x.begin(),x.end() struct Store { long pos; long oYear; long cYear; bool open(long year) { return year >= oYear && year <= cYear; } long dist(long x) { return std::abs(x - pos); } }; struct StoreType { std::vector<Store> stores; }; int main() { long numStores, numTypes, numQ; std::cin >> numStores; std::cin >> numTypes; std::cin >> numQ; std::vector<StoreType> types(numTypes); for (long s = 0; s < numStores; s++) { long pos, type, oYear, cYear; std::cin >> pos; std::cin >> type; std::cin >> oYear; std::cin >> cYear; types[type - 1].stores.push_back(Store { pos, oYear, cYear }); } for (StoreType& type : types) { std::sort(ALL(type.stores), [&] (const Store& a, const Store& b) { return a.pos < b.pos; }); } std::vector<long> minDist(numTypes); for (long i = 0; i < numQ; i++) { long pos, year; std::cin >> pos; std::cin >> year; std::fill(ALL(minDist), -1); long inconv = -1; for (StoreType& type : types) { auto it = std::lower_bound(ALL(type.stores), pos, [&] (const Store& a, long b) { return a.pos < b; }); long mid = it - type.stores.begin(); int64_t closest = INT64_MAX; long l = 0; long r = 1; while (closest != -1) { int64_t lDist = INT64_MAX; int64_t rDist = INT64_MAX; if (mid - l >= 0) { lDist = type.stores[mid - l].dist(pos); if (type.stores[mid - l].open(year)) closest = std::min(closest, lDist); } if (mid + r < type.stores.size()) { rDist = type.stores[mid + r].dist(pos); if (type.stores[mid + r].open(year)) closest = std::min(closest, rDist); } if (lDist == INT64_MAX && rDist == INT64_MAX) break; if (lDist <= rDist) l++; if (rDist <= lDist) r++; } if (closest == INT64_MAX) { inconv = -1; break; } inconv = std::max(inconv, closest); } std::cout << inconv << std::endl; } }

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:89:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (mid + r < type.stores.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...
#Verdict Execution timeMemoryGrader output
Fetching results...