QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196555#6964. WerewolvesyiyiyiAC ✓2ms3844kbC++14885b2023-10-01 19:04:192023-10-01 19:04:20

Judging History

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

  • [2023-10-01 19:04:20]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3844kb
  • [2023-10-01 19:04:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(int i=(s);i>=(t);i--)
using namespace std;
int ci(){
	int x; cin>>x; return x;
}

int n, m;

int a[33];
int ans[(int)3e6+5], tot;

void dfs(int cur, int c){
	if( cur==0 ){
		int cnt = 0, sum = 0;
		//int mx = 0;
		//rep(i,1,m) mx = max(mx, a[i]);
		//rep(i,1,m) if( a[i]==mx ) sum+=i-1, cnt++;
		rep(i,1,m) sum+=(i-1)*a[i];
		ans[++tot] = sum%m;
		//printf("line %d: mx %d sum %d %d\n", __LINE__, mx, sum, cnt);
		return;
	}
	rev_rep(i,c,1){
		a[i]++;
		dfs(cur-1, i);
		a[i]--;
	}
}

signed main(){
	int T = ci();
	while( T-- ){
		n = ci(), m = ci();
		//mp.clear();
		tot = 0;
		dfs(n-1,m);
		rep(p,0,n-1){
			rep(i,1,tot) printf("%d ", (ans[i]+p)%m+1); puts("");
		}
		//printf("line %d:\n", __LINE__);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3844kb

input:

45
5 3
7 3
14 2
8 3
9 4
6 3
4 4
7 2
11 2
12 2
7 5
9 5
9 2
5 2
19 2
16 2
6 2
6 4
2 2
12 3
5 5
10 2
8 6
18 2
7 6
13 3
10 3
8 5
17 2
10 4
8 2
11 3
15 2
8 4
4 2
6 6
9 3
20 2
13 2
5 4
7 7
7 4
3 3
21 2
6 5

output:

3 2 1 1 3 2 3 2 1 3 2 1 3 2 1 
1 3 2 2 1 3 1 3 2 1 3 2 1 3 2 
2 1 3 3 2 1 2 1 3 2 1 3 2 1 3 
3 2 1 1 3 2 3 2 1 3 2 1 3 2 1 
1 3 2 2 1 3 1 3 2 1 3 2 1 3 2 
1 3 2 2 1 3 1 3 2 1 3 2 1 3 2 2 1 3 2 1 3 1 3 2 1 3 2 1 
2 1 3 3 2 1 2 1 3 2 1 3 2 1 3 3 2 1 3 2 1 2 1 3 2 1 3 2 
3 2 1 1 3 2 3 2 1 3 2 1 3 2 1 1...

result:

ok