Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int M = 1000100;
- const long long oo =std::numeric_limits<int>::min();
- const int PW = 20;
- const int md = int(1e9) + 7;
- const int N = int(2e6)+1;
- int a[1000001];
- long long sum[1000001];
- long long ans[1000001];
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int n,m,q;
- cin>>n>>m>>q;
- int x,y;
- x=0,y=0;
- long long ans=q;
- for(int i=0;i<q;i++){
- int cl;
- cin>>cl;
- cl--;
- int x1=cl%m,y1=(cl/m);
- ans+=min(abs(n-max(y1,y)-min(y,y1)),abs(y-y1))+ min(abs(m-max(x1,x)-min(x,x1)),abs(x-x1));
- x=x1,y=y1;
- }
- cout<<ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement