QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506568#6964. WerewolvesCorzicaAC ✓2ms3640kbC++20728b2024-08-05 19:31:052024-08-05 19:31:06

Judging History

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

  • [2024-08-05 19:31:06]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3640kb
  • [2024-08-05 19:31:05]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int t, cnt, sum[21000006], n, m, now;
inline void dfs(int p, int lst = m) {
	if (p == n ) {
		sum[++cnt] = now % m;
		return;
	}
	for (int i = lst; i >= 1; i--) {
		now += i - 1;
		dfs(p + 1, i);
		now -= i - 1;
	}
}
signed main() {
//	freopen("text.in", "r", stdin);
//	freopen("text.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--) {
		cin >> n >> m;
		cnt = now = 0;
		dfs(1);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= cnt; j++) {
				cout << (sum[j] + i) % m + 1 << ' ';
			}
			cout << "\n";
		}
	}
}
//这玩意到底按什么顺序输出啊,真没看懂

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

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 
2 1 3 3 2 1 2 1 3 2 1 3 2 1 3 
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 3 2 1 3 2 3 2 1 3 2 1 3 
1 3 2 2 1 3 1 3 2 1 3 2 1 3 2 2...

result:

ok