Submission #65664

#TimeUsernameProblemLanguageResultExecution timeMemory
65664imeimi2000화살표 그리기 (KOI18_arrowH)C++17
100 / 100
67 ms5116 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n; const int inf = 2e9; vector<int> col[100001]; int x[100001]; int c[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i] >> c[i]; col[c[i]].push_back(x[i]); } for (int i = 1; i <= n; ++i) { sort(col[i].begin(), col[i].end()); } llong ans = 0; for (int i = 0; i < n; ++i) { if (col[c[i]].size() > 1) { if (lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i] + 1) - lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i]) == 1) { int v = inf; auto ri = lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i] + 1); if (ri != col[c[i]].end()) v = min(v, *ri - x[i]); auto li = lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i]); if (li != col[c[i]].begin()) v = min(v, x[i] - *(--li)); ans += v; } } } printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...