QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#918450#21608. 行列式jijidawang#WA 150ms4864kbC++141.5kb2025-02-27 20:44:042025-02-27 20:44:05

Judging History

This is the latest submission verdict.

  • [2025-02-27 20:44:05]
  • Judged
  • Verdict: WA
  • Time: 150ms
  • Memory: 4864kb
  • [2025-02-27 20:44:04]
  • Submitted

answer

#include <bits/stdc++.h>
#define filein(x) freopen(x".in", "r", stdin);
#define fileout(x) freopen(x, "w", stdout);
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout);
#define files(x) freopen(x".in", "r", stdin), freopen(x".ans", "w", stdout);
template <typename T>
inline bool inrange(T x, T l, T r){return (l <= x) && (x <= r);}
template <typename T>
inline bool inrange(T l, T r, T L, T R){return (L <= l) && (r <= R);}
template <typename T>
inline T chkmin(T& a, T b){if (a > b) a = b; return a;}
template <typename T>
inline T chkmax(T& a, T b){if (a < b) a = b; return a;}
using namespace std; // my guiding star.
using pii = pair<int, int>;
using ll = long long;
using u64 = unsigned long long;
const int N = 505, P = 998244353;
int n, a[N][N];
inline int qpow(int a, int n)
{
	int ans = 1;
	while (n)
	{
		if (n & 1) ans = 1ll * ans * a % P;
		a = 1ll * a * a % P; n >>= 1;
	}
	return ans;
}
inline int det()
{
	int ans = 1;
	for (int i=1; i<=n; i++)
	{
		int pivot = i;
		for (int j=i; j<=n; j++)
			if (a[j][i]){pivot = j; break;}
		if (!a[pivot][i]) return 0;
		if (i != pivot){ans *= -1; swap(a[i], a[pivot]);}
		for (int j=i+1; j<=n; j++)
		{
			int e = 1ll * a[j][i] * qpow(a[i][i], P - 2);
			for (int k=1; k<=n; k++) (a[j][k] -= 1ll * e * a[i][k] % P) %= P;
		}
	}
	for (int i=1; i<=n; i++) ans = 1ll * ans * a[i][i] % P;
	return (ans + P) % P;
}
int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++) scanf("%d", a[i] + j);
	printf("%d\n", det());
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 150ms
memory: 4864kb

input:

494
507979999 844753235 308697058 577366689 725069158 935333779 504374900 25818576 590205152 640101368 622693010 938297920 872742027 301114974 734834637 556531110 842083217 975440662 921805913 100862321 393656903 213191224 795146059 30475198 812681603 711143306 28681751 642978178 605226383 94538558 ...

output:

598207123

result:

wrong answer 1st numbers differ - expected: '0', found: '598207123'