# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
894533 | 2023-12-28T11:45:05 Z | salmon | Palembang Bridges (APIO15_bridge) | C++14 | 208 ms | 23844 KB |
#include <bits/stdc++.h> using namespace std; int N; int K; char c,c1; vector<pair<long long int,pair<int,int>>> v; long long int h,h1; long long int sum = 0; long long int ans = 0; long long int big = 1e18; long long int lst[100100]; int main(){ scanf(" %d",&K); scanf(" %d",&N); set<pair<int,int>> s; map<int,int> mep; for(int i = 0; i < N; i++){ scanf(" %c",&c); scanf(" %lld",&h); scanf(" %c",&c1); scanf(" %lld",&h1); if(c == c1){ ans += abs(h - h1); } else{ v.push_back(make_pair(h + h1, make_pair(h,h1))); } } sort(v.begin(),v.end()); auto it = s.begin(); lst[0] = 0; for(int i = 0; i < v.size(); i++){ if(i == 0){ sum = abs(v[i].second.second - v[i].second.first); s.insert(make_pair(v[i].second.second, mep[v[i].second.second])); mep[v[i].second.second]++; s.insert(make_pair(v[i].second.first, mep[v[i].second.first])); mep[v[i].second.first]++; it = s.begin(); } else{ int flag = 0; pair<int,int> ii = make_pair(v[i].second.first, mep[v[i].second.first] ); mep[v[i].second.first]++; pair<int,int> ii1 = make_pair(v[i].second.second, mep[v[i].second.second]); mep[v[i].second.second]++; flag += (*it) < ii; flag += (*it) < ii1; int lum = 0; if(flag == 0){ s.insert(ii); s.insert(ii1); lum += it -> first; advance(it,-1); lum -= it -> first; sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); sum += abs(lum)* 2; } if(flag == 1){ s.insert(ii); s.insert(ii1); sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); } if(flag == 2){ s.insert(ii); s.insert(ii1); advance(it,1); sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); } } lst[i + 1] = sum; } s.clear(); mep.clear(); big = sum + ans; /* for(int i = v.size() - 1; i >= 0; i--){ if(i == v.size() - 1){ sum = abs(v[i].second.second - v[i].second.first); s.insert(make_pair(v[i].second.second, mep[v[i].second.second])); mep[v[i].second.second]++; s.insert(make_pair(v[i].second.first, mep[v[i].second.first])); mep[v[i].second.first]++; it = s.begin(); } else{ int flag = 0; pair<int,int> ii = make_pair(v[i].second.first, mep[v[i].second.first] ); mep[v[i].second.first]++; pair<int,int> ii1 = make_pair(v[i].second.second, mep[v[i].second.second]); mep[v[i].second.second]++; flag += (*it) < ii; flag += (*it) < ii1; int lum = 0; if(flag == 0){ s.insert(ii); s.insert(ii1); lum += it -> first; advance(it,-1); lum -= it -> first; sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); sum += abs(lum) * 2; } if(flag == 1){ s.insert(ii); s.insert(ii1); sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); } if(flag == 2){ s.insert(ii); s.insert(ii1); advance(it,1); sum += abs(it -> first - ii.first); sum += abs(it -> first - ii1.first); } } big = min(big, lst[i] + sum); }*/ if(K == 2) printf("%lld",big + v.size() + ans); else printf("%lld", sum + ans + v.size()); } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 2 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 460 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 672 KB | Output is correct |
9 | Correct | 1 ms | 500 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 604 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 600 KB | Output is correct |
9 | Correct | 2 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 61 ms | 12780 KB | Output is correct |
13 | Correct | 208 ms | 23844 KB | Output is correct |
14 | Correct | 117 ms | 12480 KB | Output is correct |
15 | Correct | 95 ms | 14120 KB | Output is correct |
16 | Correct | 62 ms | 13760 KB | Output is correct |
17 | Correct | 108 ms | 23740 KB | Output is correct |
18 | Correct | 135 ms | 23288 KB | Output is correct |
19 | Correct | 101 ms | 23428 KB | Output is correct |
20 | Correct | 63 ms | 13996 KB | Output is correct |
21 | Correct | 121 ms | 23528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |