Cod sursa(job #2860620)

Utilizator DedzsinatorDegi Nandor Dedzsinator Data 2 martie 2022 20:45:26
Problema Traseu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <stdio.h>
#include <fstream>
using namespace std;
int a[500][500];

int main() {
    ifstream f("traseu.in");
    ofstream g("traseu.out");
    int m, n, x, ans = 0;

    f >> m >> n;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            f>>x;
            a[i][j] = x;
            if (i && a[i-1][j] < a[i][j]) a[i][j] = a[i-1][j];
            if (j && a[i][j-1] < a[i][j]) a[i][j] = a[i][j-1];
            int p = 0, q = j;
            while (p <= i && q >= 0) {
                if (a[p][q] <= x) {
                    if (i-p+j-q > ans) ans = i-p+j-q;
                    q--;
                } else p++;
            }
        }
    }

    if(ans) {
        g << ans+1 << '\n';
    } else {
        g << 0;
    }

    return 0;
}