Created
May 29, 2020 00:10
-
-
Save gbrls/e0cd19d64a2683a2b4a2732669fd2233 to your computer and use it in GitHub Desktop.
obi 2014 carteiro https://olimpiada.ic.unicamp.br/pratique/pu/2014/f1/carteiro/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() { | |
| int n,m; | |
| cin>>n>>m; | |
| map<int,int> idToCasa; | |
| for(int i=0;i<n;i++) { | |
| int aux; | |
| cin>>aux; | |
| idToCasa[aux]=i; | |
| } | |
| int pos=0; | |
| int acc=0; | |
| for(int i=0;i<m;i++) { | |
| int id; | |
| cin>>id; | |
| int nPos = idToCasa[id]; | |
| acc += abs(pos-nPos); | |
| pos = nPos; | |
| } | |
| cout<<acc<<'\n'; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment