fork(1) download
  1. #include<bits/stdc++.h>
  2. #define f(i,s,e) for(int i=s;i<e;i++)
  3. #define pb(x) push_back(x)
  4. #define all(x) x.begin(),x.end()
  5. using namespace std;
  6. map < int, vector<int> > m1,m2;
  7. int main(){
  8. int n,m,ele;
  9. cin>>n>>m;
  10. f(i,1,n+1){
  11. f(j,1,m+1){
  12. cin>>ele;
  13. m1[ele].pb(i+j);
  14. }
  15. }
  16.  
  17. f(i,1,n+1){
  18. f(j,1,m+1){
  19. cin>>ele;
  20. m2[ele].pb(i+j);
  21. }
  22. }
  23.  
  24. for(auto it:m1) sort(all(it.second));
  25. for(auto it:m2) sort(all(it.second));
  26.  
  27. cout<<endl;
  28. for(auto it:m1){
  29. for(auto x:it.second)
  30. cout<<x<<" ";
  31. cout<<endl;
  32. }
  33.  
  34. cout<<endl;
  35. for(auto it:m2){
  36. for(auto x:it.second)
  37. cout<<x<<" ";
  38. cout<<endl;
  39. }
  40. }
Success #stdin #stdout 0s 15240KB
stdin
3 4
3 4 3 3
3 7 5 5
1 1 5 3
3 3 7 3
4 1 5 5
3 1 5 3
stdout
4 5 
2 4 5 3 7 
3 
5 6 6 
4 

4 5 
2 3 5 4 7 
3 
5 6 6 
4