C 代码强制运行时错误(退出代码为-1073741819)

C 代码强制运行时错误(退出代码为-1073741819),c,runtime-error,C,Runtime Error,当我提交代码时,我一次又一次地收到这个“退出代码是-1073741819”错误。有人能帮我弄清楚吗。我正在解决这个问题 这是我写的代码。我使用的是GNUGCC115.1.0编译器 #include<stdio.h> #include<stdlib.h> #include<string.h> struct node { long int x; long int y; }space[1001]; int main() { int t

当我提交代码时,我一次又一次地收到这个“退出代码是-1073741819”错误。有人能帮我弄清楚吗。我正在解决这个问题

这是我写的代码。我使用的是GNUGCC115.1.0编译器

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
    long int x;
    long int y;
}space[1001];



int main()
{
    int t,tm;
    long i, j;
    long r, u, l, d;
    char* route[1000];

    scanf("%d", &t);
    tm = t;
    for(i = 0;i < t;i++)
    {
        scanf("%ld", &space[i].x);
        scanf("%ld", &space[i].y);
        route[i] = (char *)malloc(20000*sizeof(char));
        scanf("%s", route[i]);

    }

    for(i = 0;i < t;i++)
    {
        //initializing the left-right-up-down counters
        l = r = u = d = 0;

        for(j = 0;j < strlen(route[i]);j++)
        {
            if(route[i][j] == 'L')
                l--;
            else if(route[i][j] == 'R')
                r++;
            else if(route[i][j] == 'U')
                u++;
            else if(route[i][j] == 'D')
                d--;
        }

        //right-up
        if(space[i].x >= 0 && space[i].y >= 0)
        {

            if(space[i].x <= r && space[i].y <= u)
                printf("YES\n");

            else
                printf("NO\n");
        }
        //right-down
        else if(space[i].x >= 0 && space[i].y < 0)
        {

            if(space[i].x <= r && space[i].y >= d && d)
                printf("YES\n");

            else
                printf("NO\n");
        }
        //left-up
        else if(space[i].x < 0 && space[i].y >= 0)
        {

            if(space[i].x >= l && space[i].y <= u && l)
                printf("YES\n");

            else
                printf("NO\n");
        }
        //left-down
        else if(space[i].x < 0 && space[i].y < 0)
        {

            if(space[i].x >= l && space[i].y >= d && l && d)
                printf("YES\n");
            else
                printf("NO\n");
        }

    }




    return 0;
}
#包括
#包括
#包括
结构节点
{
长整数x;
长内质网;
}空间[1001];
int main()
{
int t,tm;
长i,j;
长r,u,l,d;
字符*路径[1000];
scanf(“%d”、&t);
tm=t;
对于(i=0;i=0&&space[i].y>=0)
{
if(空间[i].x=0)
{
if(space[i].x>=l&&space[i].y=l&&space[i].y>=d&&l&&d)
printf(“是\n”);
其他的
printf(“否”);
}
}
返回0;
}

malloc部分有错误吗?因为在codeblocks 20.03中,该代码工作正常。

您的程序只为路由字符串分配20000字节,但问题规范称其长度可能高达105,即100000。您可以期望任何在线判断测试强调问题的限制,因此它将超出分配的空间和损坏的内存

确保保存路由字符串(包括终止的空字符)需要100001字节。但是,根本不需要保存路由字符串。输入可以逐字符读取,并且当输入为b时,方向计数可以递增
l
r
u
d
此外,测试用例不需要字符串数组;每个测试用例在进入下一个测试用例之前都可以被完全处理,因此不需要一次将多个测试用例的数据保存在内存中