5个点MLE,求助

P1434 [SHOI2002] 滑雪

CUFT @ 2019-05-14 13:33:24


#include <iostream>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Inf 0x3f3f3f3f
using namespace std;

struct Point {
    int Hight;
    int Length;
} map[105][105];

struct node {
    int x,y;
} point[102*102];
bool operator<(const node p1,const node p2) {
    return map[p1.x][p1.y].Hight < map[p2.x][p2.y].Hight;
}

int f(int x,int y) {
    if( map[x][y].Length == 0 ) {
        int h = map[x][y].Hight;
        int U = map[x][y-1].Hight>h ? 0 : f(x,y-1);
        int D = map[x][y+1].Hight>h ? 0 : f(x,y+1);
        int L = map[x-1][y].Hight>h ? 0 : f(x-1,y);
        int R = map[x+1][y].Hight>h ? 0 : f(x+1,y);
        map[x][y].Length = 1 + Max(Max(U,D),Max(L,R));
    }
    return map[x][y].Length;
}

int main() {
    int c,r,ans=0;
    int t=0;
    cin>>c>>r;
    priority_queue<node> q;
    for(int i=0; i<=c+1; i++) {
        for(int j=0; j<=r+1; j++) {
            if( i==0 || j==0 || i==c+1 || j==r+1) {
                map[i][j].Hight = Inf;
            } else {
                cin>>map[i][j].Hight;
            }
            map[i][j].Length = 0;
            if( !( i==0 || j==0 || i==c+1 || j==r+1) ) {
                point[t].x = i;
                point[t].y = j;
                q.push(point[t]);
                t++;
            }
        }
    }
    node p;
    while( !q.empty() ) {
        p = q.top();
        ans = Max(ans,f(p.x,p.y));
        q.pop();
    }
    cout<<ans;
    return 0;
}```

by Lucaster_ @ 2019-05-14 13:47:51

f函数里的大于号全改成>=试试


|