228B - Two Tables - CodeForces Solution


brute force implementation *1400

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>

using namespace std;


bool ok(int x, int y, int R, int C){
    return 0 <= x && x < R && 0 <= y && y < C;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Ra, Ca; cin >> Ra >> Ca;
    vector<string> a(Ra);
    for(int i = 0; i < Ra; i ++) cin >> a[i];

    int Rb, Cb; cin >> Rb >> Cb;
    vector<string> b(Rb);
    for(int i = 0; i < Rb; i ++) cin >> b[i];

    int res = -1, resx = -1, resy = -1;
    for(int x = -max(Ra, Rb); x <= max(Ra, Rb); x ++)
        for(int y = -max(Ca, Cb); y <= max(Ca, Cb); y ++){
            int tres = 0;
            for(int ii = 0; ii < Ra; ii ++)
                for(int jj = 0; jj < Ca; jj ++){
                    if(ok(ii + x, jj + y, Rb, Cb))
                        tres += (a[ii][jj] - '0') * (b[ii + x][jj + y] - '0');
                }
            if(tres > res) res = tres, resx = x, resy = y;
        }
//    cout << res << '\n';
    cout << resx << ' ' << resy << '\n';

    return 0;
}


Comments

Submit
0 Comments
More Questions

1088B - Ehab and subtraction
1270B - Interesting Subarray
478C - Table Decorations
1304C - Air Conditioner
1311C - Perform the Combo
1519C - Berland Regional
361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem
1542C - Strange Function
961E - Tufurama
129D - String
888A - Local Extrema
722B - Verse Pattern
278A - Circle Line
940A - Points on the line
1742C - Stripes
1742F - Smaller
1742B - Increasing
1742A - Sum
1742D - Coprime
390A - Inna and Alarm Clock
1398B - Substring Removal Game
1742G - Orray
416B - Art Union
962A - Equator
803B - Distances to Zero
291A - Spyke Talks
1742E - Scuza
1506D - Epic Transformation