#42000: 為什麼會RE......


henry.rem.rem@gmail.com (*ฅ́˘ฅ̀*)

School : 臺北市立松山高級中學
ID : 278368
IP address : [223.136.74.105]
Last Login :
2024-12-27 14:56:24
b966. 3. 線段覆蓋長度 -- 2016年3月apcs | From: [61.231.15.187] | Post Date : 2024-09-17 16:25

c++
想說用差分爆破
array陣列開了題目範圍要求的大小(10^7)
範例輸入都沒問題,但丟上ZJ連#0都RE
實在想不到為什麼QQ
程式碼如下:
 
#include <iostream>
#define MAX 10000000
using namespace std;
 
int main() {
int n;
cin >> n;
int arr[MAX]{0};
while (n--) {
        int x1, x2;
        cin >> x1;
        cin >> x2;
        arr[x1]++, arr[x2]--;
    }
    int ans = arr[0] ? 1 : 0;
for (int i = 1; i < MAX; i++) {
    arr[i] += arr[i - 1];
    if (arr[i]) ans++;
}
cout << ans;
return 0;
}
 
#42987: Re: 為什麼會RE......


cges30901 (cges30901)

School : No School
ID : 30877
IP address : [39.15.1.195]
Last Login :
2024-12-23 09:25:32
b966. 3. 線段覆蓋長度 -- 2016年3月apcs | From: [39.9.74.255] | Post Date : 2024-10-14 17:16

 
#define MAX 10000000
 
int arr[MAX]{0};
 


陣列太大,建議改用vector或是動態記憶體

 
#42988: Re: 為什麼會RE......


henry.rem.rem@gmail.com (*ฅ́˘ฅ̀*)

School : 臺北市立松山高級中學
ID : 278368
IP address : [223.136.74.105]
Last Login :
2024-12-27 14:56:24
b966. 3. 線段覆蓋長度 -- 2016年3月apcs | From: [1.161.62.7] | Post Date : 2024-10-14 17:24

 
#define MAX 10000000
 
int arr[MAX]{0};
 


陣列太大,建議改用vector或是動態記憶體

喔喔喔喔

OK懂了


感謝大大的回覆:D

好人一生平安

 
ZeroJudge Forum