#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |