제출 #1172093

#제출 시각아이디문제언어결과실행 시간메모리
11720932200040225Palembang Bridges (APIO15_bridge)C++20
0 / 100
3 ms320 KiB
#include <iostream> #include <vector> #include <cmath> #include <string> using namespace std; long long computeMinDistance(int N, vector<pair<char, int>> home, vector<pair<char, int>> work) { long long total_distance = 0; for (int i = 0; i < N; i++) { char home_zone = home[i].first; int home_building = home[i].second; char work_zone = work[i].first; int work_building = work[i].second; if (home_zone == work_zone) { total_distance += abs(home_building - work_building); } else { total_distance += abs(home_building - work_building) + 1; } } return total_distance; } int main() { int K, N; cin >> K >> N; vector<pair<char, int>> home(N), work(N); for (int i = 0; i < N; i++) { string entry; cin >> entry; home[i] = {entry[0], stoi(entry.substr(1, entry.find('A') - 1))}; work[i] = {entry[entry.find('A')], stoi(entry.substr(entry.find('A') + 1))}; } cout << computeMinDistance(N, home, work) << endl; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...