Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author : pedrocas
- * Date : 2023 Sep 24 11:44:35 AM
- */
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const long long mod = 1000000007;
- ll gcd (ll a, ll b) {return b==0 ? a : gcd(b, a%b);}
- #define all(c) (c).begin(),(c).end()
- #define pb push_back
- #define mp make_pair
- #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
- const int di4[] = {-1, 0, 1, 0};
- const int dj4[] = { 0, 1, 0, -1};
- const int di8[] = {-1, 0, 1, 0, -1, 1,-1,1};
- const int dj8[] = { 0, 1, 0, -1, -1, 1,1,-1};
- const int maxn = 2e5 + 10;
- const ll INF = 1e18;
- int main()
- {
- #ifdef LOCAL
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- #endif
- fastio
- int tc = 1;
- //cin >> tc;
- while(tc-- ){
- int n, k;cin >> n >> k;
- vector<int> v[n];
- map<int, int> pos[n];
- for(int i = 0; i<n; i++){
- for(int j = 0, x; j<k; j++){
- cin >> x;
- v[i].pb(x);
- pos[i][x] = j;
- }
- }
- vector<int> b = v[0];
- vector<int> c[n];
- vector<int> mx(n + 1, 0);
- int cnt = 0, ans = 1;
- mx[1] = 1;
- for(int i = 0; i<k; i++){
- int el = b[i];
- bool ok = true;
- for(int j = 1; ok&&j<n; j++){
- if(c[j].size() == 0){
- c[j].pb(pos[j][el]);
- }else{
- if(c[j].back() + 1 != pos[j][el]){
- ok = false;
- }else{
- c[j].push_back(pos[j][el]);
- }
- }
- }
- if(ok){
- ans = max(ans, ++cnt);
- mx[cnt]++;
- }else{
- cnt = 0;
- for(int j = 1; j< n; j++){
- c[j].clear();
- }
- }
- }
- if(ans == 1){
- cout << 1 << " " << mx[ans] <<endl;
- }else cout << ans << " " <<mx[ans]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement