CDEC2206 - Editorial

PROBLEM LINK:

Practice

Author: Parth Chandan(pc_283 | CodeChef User Profile for PARTH CHANDAN | CodeChef)
Tester: Pradeep(pradeep___ | CodeChef User Profile for Pradeep Kumar Sahu | CodeChef)
Editorialist: Parth Chandan(pc_283 | CodeChef User Profile for PARTH CHANDAN | CodeChef)

DIFFICULTY:

EASY-MEDIUM

PREREQUISITES:

Matrices

PROBLEM:

You were given a matrix and you had to find the minimum dimension of a rectangle possible such that it contains all the drawn area.

EXPLANATION:

You had to just use the first occuring drawn area and last occuring drawn area in both horizontal direction and vertical direction which will give you the minimum area of the rectangle.

SOLUTIONS:

Setter's Solution
    #include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        
        int t;
        cin>>t;
        while(t--){
            int p,q,n1,m1,n2,m2;
            cin>>p>>q>>n1>>m1;
            char a[n1][m1];
            for(int i=0;i<n1;i++){
                for(int j=0;j<m1;j++){
                    cin>>a[i][j];
                }
            }
            cin>>n2>>m2;
            char b[n2][m2];
            for(int i=0;i<n2;i++){
                for(int j=0;j<m2;j++){
                    cin>>b[i][j];
                }
            }
            long long qw=0;
            if(p>q){
                cout<<"Netherlands ";
                qw=q;
            }else{
                cout<<"Argentina ";
                qw=p;
            }
            int amn=INT_MAX,amx=INT_MIN,bmn=INT_MAX,bmx=INT_MIN;
            for(int i=0;i<n1;i++){
                for(int j=0;j<m1;j++){
                    if(a[i][j]=='#'){
                        amn=min(amn,i);
                        amx=max(amx,i);
                        bmn=min(bmn,j);
                        bmx=max(bmx,j);
                    }
                }
            }
            int x=(amx-amn+1)*(bmx-bmn+1);
            amn=INT_MAX; amx=INT_MIN; bmn=INT_MAX; bmx=INT_MIN;
            for(int i=0;i<n2;i++){
                for(int j=0;j<m2;j++){
                    if(b[i][j]=='#'){
                        amn=min(amn,i);
                        amx=max(amx,i);
                        bmn=min(bmn,j);
                        bmx=max(bmx,j);
                    }
                }
            }
            int y=(amx-amn+1)*(bmx-bmn+1);
            long long qa=0;
            if(x<y){
                cout<<"1 ";
                qa=x;
            }else{
                cout<<"2 ";
                qa=y;
            }
            long long f=qw*qa;
            cout<<f<<"\n";
        }
        return(0);
    }
Tester's Solution
    #include <bits/stdc++.h>
    using namespace std;
    
    long long findarea()
    {
        int n , m;
        int r1 = INT_MAX, r2 = -1, c1 = INT_MAX, c2 = -1;
        cin >> n >> m;
        char ar[n][m];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cin >> ar[i][j];
                if (ar[i][j] == '#')
                {
                    r1 = min(r1, i);
                    r2 = max(r2, i);
                    c1 = min(c1, j);
                    c2 = max(c2, j);
                }
            }
        }
    
        long long area = 0;
        if ((r2 != -1) && (c2 != -1))
            area = ((r2 - r1 + 1) * 1LL * (c2 - c1 + 1));
    
        return area;
    }
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
            long long p, q;
            cin >> p >> q;
            long long mn = min(p, q);
    
            long long area1 = findarea();
            long long area2 = findarea();
    
            long long v1 = area1 * p, v2 = area1 * q, v3 = area2 * p, v4 = area2 * q;
            if (area1 >= area2)
            {
                if (v3 <= v4)
                    cout << "Argentina 2 " << v3 << endl;
                else
                    cout << "Netherlands 2 " << v4 << endl;
            }
            else
            {
                if (v1 <= v2)
                    cout << "Argentina 1 " << v1 << endl;
                else
                    cout << "Netherlands 1 " << v2 << endl;
            }
        }
        return 0;
    }