Advertisement
Guest User

Untitled

a guest
Sep 24th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. /*
  2.  * Author : pedrocas
  3.  * Date   : 2023 Sep 24 11:44:35 AM
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11. const long long mod = 1000000007;
  12. ll gcd (ll a, ll b) {return b==0 ? a : gcd(b, a%b);}
  13.  
  14. #define all(c) (c).begin(),(c).end()
  15. #define pb push_back
  16. #define mp make_pair
  17. #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
  18.  
  19. const int di4[] = {-1, 0, 1,  0};
  20. const int dj4[] = { 0, 1, 0, -1};
  21. const int di8[] = {-1, 0, 1,  0, -1, 1,-1,1};
  22. const int dj8[] = { 0, 1, 0, -1, -1, 1,1,-1};
  23.  
  24. const int maxn = 2e5 + 10;
  25. const ll INF = 1e18;
  26.  
  27. int main()
  28. {
  29. #ifdef LOCAL
  30.     freopen("input.txt", "rt", stdin);
  31.     freopen("output.txt", "wt", stdout);
  32. #endif
  33.     fastio
  34.     int tc = 1;
  35.     //cin >> tc;
  36.     while(tc-- ){
  37.         int n, k;cin >> n >> k;
  38.         vector<int> v[n];
  39.         map<int, int> pos[n];
  40.         for(int i = 0; i<n; i++){
  41.             for(int j = 0, x; j<k; j++){
  42.                 cin >> x;
  43.                 v[i].pb(x);
  44.                 pos[i][x] = j;
  45.             }
  46.         }
  47.         vector<int> b = v[0];
  48.         vector<int> c[n];
  49.         int cnt = 0, ans = 1;
  50.         for(int i = 0; i<k; i++){
  51.             int el = b[i];
  52.             bool ok = true;
  53.             for(int j = 1; ok&&j<n; j++){
  54.                 if(c[j].size() == 0){
  55.                     c[j].pb(pos[j][el]);   
  56.                 }else{
  57.                     if(c[j].back() + 1 != pos[j][el]){
  58.                         ok = false;
  59.                     }else{//faltava a porra deste else
  60.                         c[j].push_back(pos[j][el]);
  61.                     }
  62.                 }  
  63.             }
  64.             if(ok){
  65.                 ans = max(ans, ++cnt);
  66.             }else{
  67.                 cnt = 0;
  68.                 for(int j = 1; j< n; j++){
  69.                     c[j].clear();
  70.                 }
  71.             }
  72.         }
  73.         if(ans == 1){
  74.             cout << 1 << " " << n <<endl;
  75.         }else cout << ans << " " <<1<<endl;
  76.     }
  77.     return 0;
  78. }
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement