Cod sursa(job #3283284)

Utilizator t.fippyTiron Filip t.fippy Data 8 martie 2025 21:21:20
Problema Plantatie Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#include <thread>
using namespace std;

ifstream fin("plantatie.in");
ofstream fout("plantatie.out");

void getMax(int a[501][501], int x, int y, int k, int& result) {
    int maxim = 0;
    for (int i = x; i<x+k; ++i)
        for (int j = y; j<y+k; ++j)
            maxim = max(maxim, a[i][j]);
    result = maxim;
}

int main() {
    int n, m;
    fin>>n>>m;
    int a[501][501];
    for (int i = 1; i <=n; ++i)
        for (int j = 1; j<=n; ++j)
            fin>>a[i][j];

    int x, y, k;
    vector<thread> threads;
    vector<int> results(m);

    for (int t = 0; t < m; ++t) {
        fin >> x >> y >> k;
        threads.push_back(thread(getMax, a, x, y, k, ref(results[t])));
    }
    for (auto& th : threads) th.join();
    for (const int& result : results) fout << result << endl;
    return 0;
}