C++ 1AC 9RE 求助

P1047 [NOIP2005 普及组] 校门外的树

lyxsunday @ 2022-08-07 17:32:31

https://www.luogu.com.cn/record/82834528


by lyxsunday @ 2022-08-07 17:32:59

↑我的提交记录


by lyxsunday @ 2022-08-07 17:34:19

#include<bits/stdc++.h>
using namespace std;
int l,m,L,R,ans;
bool tree[1001]; 
int main()
{
    cin>>l>>m;
    for(int i=1;i<=l;i++)
    {
        tree[i]=true;
    }
    for(int i=1;i<=m;i++)
    {
        cin>>L>>R;
        for(int j=L;j<=R;j++)
        {
            tree[j]=false;
        }
    }
    for(int i=1;i<=l;i++)
    {
        if(tree[i]==true)
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

by IGJHL @ 2022-08-07 17:36:08

RE 一般是数组开小了,题目中说 1 \le l \le 10^410^4 = 10000,而你数组只开了 1000


by lyxsunday @ 2022-08-07 17:36:39

啊,我我瞎了


by lyxsunday @ 2022-08-07 17:37:03

@OI_Loser_IGJHL 感谢提醒


by lyxsunday @ 2022-08-07 17:37:50

https://www.luogu.com.cn/record/82835549


by IGJHL @ 2022-08-07 17:38:58

@lyxsunday 我看看


by lyxsunday @ 2022-08-07 17:39:15

QwQ 变成 1AC 9WA 了


by lyxsunday @ 2022-08-07 17:40:44

下载了第二个测试点发现我的答案比正确答案少了1


by IGJHL @ 2022-08-07 17:43:11

0,1,2,\dots,l,都种有一棵树。这是题目中的话,依题意 0 处也有一棵树,你的代码没有考虑到.


| 下一页