矩阵乘法代码在没有任何输入的情况下RE,求大佬解答
  • 板块学术版
  • 楼主Sudohry
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/3/17 13:52
  • 上次更新2023/10/23 21:21:11
查看原帖
矩阵乘法代码在没有任何输入的情况下RE,求大佬解答
388415
Sudohry楼主2023/3/17 13:52

RT

运行时会在不作任何输入的时候卡住,然后显示停止运行

实测数组大小开到105之后可以正常运行

但我认为并非空间问题(当删去d的相关内容之后空间减少1/4不会RE,但把ll改成int之后空间减少1/2仍然RE)

#include <bits/stdc++.h>

#define rep(i, l, r) for (int i=(l); i<=(r); ++i)
#define per(i, r, l) for (int i=(r); i>=(l); --i)
#define N 505
#define ll long long
#define mod (998244353ll)


using namespace std;


int n;
bool found;


struct rec {
	ll a[N][N];
//	rec () { memset (a, 0, sizeof a); }
	bool operator != (const rec &x) const {
		rep (i, 1, n) if (a[1][i] != x.a[1][i]) return false;
		return true;
	}
	rec operator * (const rec &x) const {
		rec ans;
		for (int k=1; k<=n; ++k)
//			for (int i=1; i<=ans.n; ++i)
				for (int j=1; j<=n; ++j) {
					ans.a[1][j] += a[1][k] * x.a[k][j] % mod;
					ans.a[1][j] %= mod;
				}
		return ans;
	}
//	inline void pre () {
//		for (int i=1; i<=n; ++i) a[i][i] = 1;
//	}
} a, b, c, d;


int main () {
	srand (time (0));
	while (scanf ("%d", &n) != EOF) {
		rep (i, 1, n) rep (j, 1, n) scanf ("%lld", &a.a[i][j]);
		rep (i, 1, n) rep (j, 1, n) scanf ("%lld", &b.a[i][j]);
		rep (i, 1, n) rep (j, 1, n) scanf ("%lld", &c.a[i][j]);
		found = false;
//		a.n = b.n = c.n = n;
//		a.m = b.m = c.m = n;
//		d.n = 1; d.m = n;
		rep (i, 1, 10) {
			rep (j, 1, n) d.a[1][j] = rand () + 1;
			if (d*a*b != d*c) {
				printf ("NO\n");
				found = true;
				break ;
			}
		}
		if (!found) printf ("YES\n");
	}
	return 0;
}

/*

2
1 0
2 3
5 1
0 8
5 1
10 26

*/
2023/3/17 13:52
加载中...