问题遇到的现象和发生背景
今天发现开这么大的数组不行 long long num[1000000][1000000],L[1000000];编译错误;但是我新建了一个源文件试一下开更大的数组long long num[100000000][100000000],L[100000000];可以运行。请问为什么会这样?这是咋回事啊??以及用vector<vector> num;是可以的。题目网址,有兴趣的可以看看:https://atcoder.jp/contests/abc233/tasks/abc233_c
问题相关代码,请勿粘贴截图
代码1可以正常运行:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
const int MAX=10010;
int s[100];
int main(){
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll b[100000000][100000000],L[100000000];
b[0][0]=1000101010;
cout<<b[0][0]<<endl;
return 0;
}
代码2使用stl:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define ll long long
#define MAX 100005
vector<vector<ll>> num;
ll N,X,cnt=0,cop,L;
void sol(ll col){
rep(i,0,num[col].size()){
if(cop%num[col][i]==0){
cop/=num[col][i];
if(col==N-1&&cop==1){
cnt++;
}
else if(col!=N-1){
sol(col+1);
}
cop*=num[col][i];
}
}
}
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin>>N>>X;
num.resize(N);
cop=X;
rep(i,0,N){
cin>>L;
num[i].resize(L);
rep(j,0,L){
cin>>num[i][j];
}
}
sol(0);
cout<<cnt<<endl;
}
代码3编译错误的代码:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define ll long long
#define MAX 100005
ll num[1000000][1000000],L[1000000];
ll N,X,cnt=0,cop;
void sol(ll col){
//cout<<cnt<<'*'<<endl;
rep(i,0,L[col]){
if(cop%num[col][i]==0){
cop/=num[col][i];
if(col==N-1&&cop==1){
cnt++;
}
else if(col!=N-1){
sol(col+1);
}
cop*=num[col][i];
}
}
}
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin>>N>>X;
cop=X;
rep(i,0,N){
cin>>L[i];
rep(j,0,L[i]){
cin>>num[i][j];
}
}
sol(0);
cout<<cnt<<endl;
}
运行结果及报错内容
Error: value of 00000746a5a29223 too large for field of 4 bytes at 0000000000000003
Error: value of 00000746a5a29327 too large for field of 4 bytes at 0000000000000107
我的解答思路和尝试过的方法
我想要达到的结果
em.为啥代码1代码2可以正常运行代码3却不行?