QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506516 | #6964. Werewolves | Corzica | TL | 0ms | 0kb | C++20 | 1.2kb | 2024-08-05 18:42:25 | 2024-08-05 18:42:26 |
answer
#include<bits/stdc++.h>
using namespace std;
int t, cnt, sum[2100006], n, m, now, jie[10005];
inline void dfs(int p) {
if (p == m) {
sum[++cnt] = now % m;
return;
}
for (int i = 1; i <= m; i++) {
now += i;
dfs(p + 1);
now -= i;
}
}
inline void solve(int pre, int suf, int ssum) {
for (int i = 1; i <= jie[pre]; i++) {
for (int j = 1; j <= cnt; j++) {
int p = (ssum - sum[j] + m) % m;
if (!p) p = m;
for (int k = 1; k <= jie[suf]; k++) {
cout << p << ' ';
}
}
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
jie[0] = 1;
for (int i = 1; i <= n; i++) {
jie[i] = jie[i - 1] * m;
}
if (n < m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= jie[n - 1]; j++) {
cout << 1 << ' ';
}
cout << "\n";
}
continue;
}
cnt = 0, now = 0;
dfs(1);
for (int i = 1; i <= n / m; i++) {
for (int j = (i - 1) * m + 1; j <= i * m; j++) {
solve((i - 1)*m, n - i * m, j % m);
}
}
for (int i = (n / m) * m + 1; i <= n; i++) {
for (int j = 1; j <= jie[n - 1]; j++) {
cout << 1 << ' ';
}
cout << "\n";
}
}
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
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:
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3...