QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72367#5031. 核zhoukangyang10 18ms5504kbC++171.7kb2023-01-15 15:02:382023-01-15 15:04:01

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 15:04:01]
  • 评测
  • 测评结果:10
  • 用时:18ms
  • 内存:5504kb
  • [2023-01-15 15:02:38]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
using namespace std;
const int N = 1145;

int n, q, mod;
int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}

int a[N][N];

int f[N][N];
int det(int n) {
	int p = 1;
	L(i, 1, n) {
		L(j, p + 1, n) {
			while(f[j][i]) {
				int t = f[p][i] / f[j][i];
				L(k, i, n) (f[p][k] += q - (ll) f[j][k] * t % q) %= q;
				swap(f[p], f[j]);
			}
		}
		if(f[p][i]) ++p;
	}
	return p - 1;
}

int ans[N];

void search(int x, int y) {
	if(y == n + 1) ++x, y = 1;
	if(x == n + 1) {
		L(i, 1, n) {
			L(j, 1, n) {
				f[i][j] = a[i][j];
			}
		} 
		if(det(n) != n) 
			return ;
		
		L(i, 1, n) {
			L(j, 1, n) {
				f[i][j] = a[i][j];
			}
		} 
		
		L(i, 1, n) 
			(f[i][i] += q - 1) %= q;
//		L(i, 1, n) {
//			L(j, 1, n) {
//				cout << f[i][j] << ' ';
//			}
//			cout << '\n';
//		}
//		cout << '\n';
		
//		cout << "det : " << det(n) << '\n';

		ans[det(n)] += 1;
		return ; 
	}
	L(i, 0, q - 1) {
		a[x][y] = i;
		search(x, y + 1);
	}
}

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> q >> mod; 
	search(1, 1);
	int pw = 1, s = 1;
	L(i, 1, n) pw = (ll) pw * q % (mod - 1);
	int ns = 0;
	R(i, n, 0) {
		(ns += (ll) ans[i] * qpow(3, s) % mod) %= mod;
		s = (ll) s * pw % (mod - 1);
	}
	cout << ns << '\n';
	return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 5348kb

input:

1 2 540053233

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 2ms
memory: 5504kb

input:

2 2 156542707

output:

43046970

result:

ok 1 number(s): "43046970"

Test #3:

score: 0
Accepted
time: 2ms
memory: 5364kb

input:

1 2 186225229

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: 0
Accepted
time: 18ms
memory: 5348kb

input:

3 3 109884329

output:

100602209

result:

ok 1 number(s): "100602209"

Test #5:

score: 0
Accepted
time: 2ms
memory: 5424kb

input:

1 2 144802297

output:

9

result:

ok 1 number(s): "9"

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #6:

score: 0
Time Limit Exceeded

input:

20 21992843 328859143

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Memory Limit Exceeded

Test #26:

score: 0
Memory Limit Exceeded

input:

998818 198334853 998244353

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

9909956 720431399 720431401

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%