记录编号 559460 评测结果 AAAAAAAAAA
题目名称 送给圣诞夜的礼品 最终得分 100
用户昵称 GravatarOasiz 是否通过 通过
代码语言 C++ 运行时间 0.013 s
提交时间 2021-03-10 20:15:05 内存使用 1.32 MiB
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MN = 101;
int N, M;
struct mat {
	int m[MN][MN];
} d[11];
mat operator *(mat &a,mat &b){
	mat r;
	memset(r.m, 0, sizeof(r.m));
	for(int i=1; i<=N; i++)
		for(int j=1; j<=N; j++) {
			if(a.m[i][j]) {
				for(int k=1; k<=N; k++)
					r.m[i][k]+=a.m[i][j]*b.m[j][k];
			}
		}
	return r;
}
mat operator ^(mat a,int n) {
	mat r;
	memset(r.m, 0, sizeof(r.m));
	for(int i = 1; i <= N; i++){
		r.m[i][i] = 1;
	}
	while(n) {
		if(n&1) r=r*a;
		n>>=1;
		a=a*a;
	}
	return r;
}
signed main() {
	freopen("christgift.in","r",stdin);
	freopen("christgift.out","w",stdout);
	int K,x;
	mat tmp;
	scanf("%d%d%d", &N, &M, &K);
	memset(tmp.m, 0, sizeof(tmp));
	for(int i = 1; i <= N; i++){
		tmp.m[i][i] = 1;
	}
	for(int i = 1; i <= M; i++) {
		memset(d[i].m, 0, sizeof(d[i].m));
		for(int k = 1; k <= N; k++) {
			scanf("%d", &x);
			d[i].m[k][x] = 1;
		}
		tmp = d[i]*tmp;
	}
	int tt = K/M;
	tmp = tmp^tt;
	mat ans;
	memset(ans.m, 0, sizeof(ans.m));
	for(int i = 1; i <= N; i++) {
		ans.m[i][1] = i;
	}
	ans = tmp*ans;
	tt = K%M;
	for(int k = 1; k <= tt; k++) {
		ans = d[k]*ans;
	}
	for(int i=1;i<=N;i++) {
		printf("%d ", ans.m[i][1]);
	}
	return 0;
}