Rima

Problem Link

Solution by Mr.Olimpia — 100 pts

Code / Notes

#include <bits/stdc++.h>
using namespace std;

// https://ide.usaco.guide/Ov5Bu8j7yJ_6itiOaT2

// P[3] = 5 -> o pai do 3 é o 5
// P[3] = -1 -> 3 não tem pai

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<string>> L (n, vector<string>(m));
    for(int i=0; i< n; i++){
        for(int j=0; j<m; j++){
            cin >> L[i][j];
        }
    }
    int ans1=0;
    int ans2=0;
    int ans3=0;
    for(int i=0; i<n; i=i+4){
        if(L[i][m-1].size()>=k and L[i+1][m-1].size()>=k and L[i+2][m-1].size()>=k and L[i+3][m-1].size()>=k){
            int x1=0;
            int x2=0;
            int x3=0;
            for(int j=0; j<k; j++){
                if(L[i][m-1][L[i][m-1].size()-k+j]==L[i+1][m-1][L[i+1][m-1].size()-k+j] and L[i+2][m-1][L[i+2][m-1].size()-k+j]==L[i+3][m-1][L[i+3][m-1].size()-k+j]){
                    x1++;
                }
                if(L[i][m-1][L[i][m-1].size()-k+j]==L[i+2][m-1][L[i+2][m-1].size()-k+j] and L[i+1][m-1][L[i+1][m-1].size()-k+j]==L[i+3][m-1][L[i+3][m-1].size()-k+j]){
                    x2++;
                }
                if(L[i][m-1][L[i][m-1].size()-k+j]==L[i+3][m-1][L[i+3][m-1].size()-k+j] and L[i+1][m-1][L[i+1][m-1].size()-k+j]==L[i+2][m-1][L[i+2][m-1].size()-k+j]){
                    x3++;
                }
            }
            if(x1==k){
                ans1++;
            }
            if(x2==k){
                ans2++;
            }
            if(x3==k){
                ans3++;
            }
        }
    }
    cout << ans1 << " " << ans2 << " " << ans3;

}

Last updated 1 month, 3 weeks ago


« Back to problem