Jump to content

invalid next size (fast)

RexLee
#include <iostream>#include <vector>#include <queue>#include <utility>#include <string>#include <climits>int solve(const std::vector<std::vector<char> > &maze, int cati, int catj, int mousei, int mousej, int n, int len){    int dx[4] = {1, 0, -1, 0};    int dy[4] = {0, 1, 0, -1};    typedef std::pair<int, int> p;    std::queue<p> que;    std::vector<std::vector<int> > d;    d.resize(n);    for (int i = 0; i < n; ++i)        d[i].resize(n);    for (int i = 0; i < n; ++i)        for (int j = 0; j < len; ++j)            d[i][j] = INT_MAX;    que.push(p(cati, catj));    d[cati][catj] = 0;    while (que.size())    {        p tmp = que.front();        que.pop();        if (tmp.first == mousei && tmp.second == mousej) break;        for (int i = 0; i < 4; ++i)        {            int ni = tmp.first + dx[i], nj = tmp.second + dy[i];            if (ni >= 0 && ni < n && nj >= 0 && nj < len && maze[ni][nj] != '#' && d[ni][nj] == INT_MAX)            {                que.push(p(ni, nj));                d[ni][nj] = d[tmp.first][tmp.second] + 1;            }        }    }    if (d[mousei][mousej] == INT_MAX)        std::cout << "= =\"" << std::endl;    else         std::cout << d[mousei][mousej] << std::endl;}int main(){    const int N = 100 + 10;    int n;    int cati, catj;    int mousei, mousej;    int len;    std::vector<std::vector<char> > maze;    maze.resize(N);    for (int i = 0; i < N; ++i)        maze[i].resize(N);    while (std::cin >> n)    {        if (n == 0) break;        char c = std::cin.get();        std::string input;        for (int i = 0; i < n; ++i)        {            int cnt = 0;            std::getline(std::cin, input);            len = input.length();            for (int j = 0; j < input.length(); ++j)            {                if (input[j] == 'K') {cati = i; catj = j;}                else if (input[j] == '@') {mousei = i; mousej = j;}                maze[i][cnt++] = input[j];            }        }        solve(maze, cati, catj, mousei, mousej, n, len);    }    return 0;}

This is a program(c++) to solve a bfs problem. But when send it to the online judge it gives me invalid next size(fast). What did I do wrong in the program? It also crashes when after I enter a input.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×