Advertisement
rotti321

traseu3 50pct

Jun 6th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. short n, m;
  5. int citit;
  6.  
  7. map<int, pair<int, int>>mp;
  8.  
  9. int main()
  10. {
  11. ifstream cin("traseu.in");
  12. ofstream cout("traseu.out");
  13. cin>>n>>m;
  14. for(short i = 1; i<=n; i++){
  15. for(int j = 1; j<=m; j++){
  16. cin>>citit;
  17. mp[citit] = {i, j};
  18. }
  19. }
  20. int maxim = 0;
  21. for(int i = 1; i<=n*m-1; i++){
  22. for(int j = i+1; j<=n*m; j++){
  23. if(mp[j].first >= mp[i].first && mp[j].second>=mp[i].second){
  24. maxim = max(maxim, abs(mp[j].first - mp[i].first) + abs(mp[j].second-mp[i].second)+1);
  25. }
  26. }
  27. }
  28. cout<<maxim;
  29.  
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement