RE是怎么回事,我觉得数组已经开得够大了

P3613 【深基15.例2】寄包柜

Lmm_a @ 2021-09-10 18:17:19


#include<bits/stdc++.h>
using namespace std;
int b[100000000],f[10009][10009],m[200000000];
int main(){
    int n,q,c,x,y,z,v=0;
    cin>>n>>q;
    for(int i=1;i<=q;i++){
        cin>>c;
        if(c==1){
        cin>>x>>y>>z;
        f[x][y]=1;
        b[y]=z;
        }
        else {
            cin>>x>>y;
            if(f[x][y]==1){
                m[++v]=b[y];
            }
        }   
    }
    for(int i=1;i<=v;i++){
        cout<<m[i]<<endl;
    } 
    return 0;
}

by Ninelife_Cat @ 2021-09-10 18:20:18

@Lmm_a 您数组开太大了


by Acfboy @ 2021-09-10 18:45:51

《数组已经开得够大了》


by Yikara @ 2021-09-10 18:48:27

vector?


by Lmm_a @ 2021-09-10 20:13:38

@Ninelife_Cat 那个,我不太明白,数组开太大也会RE???


by Lmm_a @ 2021-09-10 20:15:20

@Acfboy 所以我把数组改小了还是不行,应该换种思路还是怎么改


by Acfboy @ 2021-09-10 20:46:17

@Lmm_a 用 std::vector


by Joe_20080720 @ 2021-09-22 20:56:10

用容器


by I_Wanna_AC @ 2022-07-21 16:54:58

换vector试逝

#include<bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll;
const int N=1e5+2;
vector<int> a[N];
int main(){
    int n,q,b,c,d;
    cin>>n>>q;
    int t,i,j,k;
    while(q--)
    {
        cin>>t;
        if(t==1)
        {
            cin>>i>>j>>k;
            if(a[i].size()<j+1){
                a[i].resize(j+1);
            }
            a[i][j]=k;
        }
        else if(t==2)
        {
            cin>>i>>j;
            cout<<a[i][j]<<endl;
        }
    }
    return 0;
}

|