Cod sursa(job #3236410)

Utilizator DomnulMilandruMilandru Nicon-David DomnulMilandru Data 28 iunie 2024 14:31:50
Problema Matrix Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb

#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream cin("matrix.in");
ofstream cout("matrix.out");
int n,m;
char x;
vector<vector<char>> A;
unordered_map<int,int> M;
vector<int> fr;
int main()
{
    cin>>n>>m;
    A.resize(n+1);
    for(int i=1;i<=n;i++)
    {
        A[i].resize(n+1);
        for(int j=1;j<=n;j++)
           cin>>A[i][j];
    }
    for(int i=1;i<=m;i++)
      for(int j=1;j<=m;j++)
      {
        cin>>x;
        M[x-'a']++;
      }
    int ans=0;
    for(int i=1;i<=n-m+1;i++)
      for(int j=1;j<=n-m+1;j++)
      {
        fr.resize(0);
        fr.resize(26);
        for(int x=i;x<i+m;x++)
          for(int y=j;y<j+m;y++)
            fr[A[x][y]-'a']++;
        bool ok=1;
        for(int i=0;i<26;i++)
          if(M[i]!=fr[i])
          {
              ok=0;
              break;
          }
        if(ok)
          ans++;
      }
    cout<<ans;
    return 0;
}