为什么Runtime Error???!

P1434 [SHOI2002] 滑雪

visitor @ 2017-08-05 10:20:51

#include <iostream>
#include <algorithm>
using namespace std;
int map[110][111] = {0};
int len[110][111] = {0};
struct stu{
    int num = 0;
    int x = 0;
    int y = 0;
};
stu a[10010];
int ai = 0;
int movex[4] = {0, 0, -1, 1};
int movey[4] = {1, -1, 0, 0};
bool comp_num(const stu &a, const stu &b)
{
    return a.num <= b.num;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> map[i][j];
            a[++ai].num = map[i][j];
            a[ai].x = i;
            a[ai].y = j;
            len[i][j] = 1;
        }
    }
    sort(a + 1, a + ai + 1, comp_num);
    int maxLen = 1;
    for(int i = 1; i <= ai; i++)
    {
        int nx = a[i].x;
        int ny = a[i].y;
        for(int j = 0; j < 4; j++)
        {
            int xxx = nx + movex[j];
            int yyy = ny + movey[j];
            if(xxx >= 1 && xxx <= n && yyy >= 1 && yyy <= m)
            {
                if(map[xxx][yyy] >= map[nx][ny])
                {
                    continue;
                }
                if(len[nx][ny] < len[xxx][yyy] + 1)
                {
                    len[nx][ny] = len[xxx][yyy] + 1;
                    if(maxLen < len[nx][ny])
                    {
                        maxLen = len[nx][ny];
                    }
                }
            }
        }
    }
    cout << maxLen;
    return 0;
}

by Akihito @ 2017-08-25 11:10:40

队列a[]开小了

然而开大了之后变TLE。。。

所以还要优化


by Akihito @ 2017-08-25 11:11:04

@护花使者akakak


by 菜鸟ztc @ 2017-09-09 14:51:45

蒟蒻认为是数组开得太大了,我也有过类似情况


|