QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107752 | #5380. Bell Ringing | PetroTarnavskyi# | TL | 59ms | 7680kb | C++17 | 1.6kb | 2023-05-22 18:42:08 | 2023-05-22 18:42:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
VI g[74747];
VI ans;
int deg[74747];
bool used[74747];
int dg;
int md = 6;
void dfs(int v)
{
used[v] = 1;
ans.PB(v);
vector<PII> a;
for (auto to : g[v])
{
if (!used[to])
{
deg[to]--;
a.PB({deg[to] + (rand() % md), to});
}
}
sort(ALL(a));
if (SZ(a))
dfs(a[0].second);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
srand(30);
int n;
cin >> n;
if (n == 8) md = 12;
VI v(n);
iota(ALL(v), 1);
vector<VI> p;
do
{
p.PB(v);
}while(next_permutation(ALL(v)));
FOR(i, 0, SZ(p))
{
FOR(j, i + 1, SZ(p))
{
bool ok = 1;
FOR(k, 0, n)
{
if (!((k > 0 && p[j][k - 1] == p[i][k]) || (p[j][k] == p[i][k]) || (k < n - 1 && p[j][k + 1] == p[i][k])))
{
ok = false;
break;
}
}
if (ok)
{
g[i].PB(j);
g[j].PB(i);
deg[i]++;
deg[j]++;
}
}
}
dg = deg[0];
int mx = 0;
do
{
ans.clear();
FOR(i, 0, SZ(p))
{
deg[i] = dg;
used[i] = false;
}
dfs(0);
mx = max(mx, SZ(ans));
} while (SZ(ans) != SZ(p));
FOR(i, 0, SZ(ans))
{
FOR(j, 0, n)
{
cout << p[ans[i]][j] << ' ';
}
cout << '\n';
}
cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5588kb
input:
2
output:
1 2 2 1
result:
ok Thank you for your great code. It was fantastic.
Test #2:
score: 0
Accepted
time: 3ms
memory: 5376kb
input:
3
output:
1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3
result:
ok Thank you for your great code. It was fantastic.
Test #3:
score: 0
Accepted
time: 3ms
memory: 5440kb
input:
1
output:
1
result:
ok Thank you for your great code. It was fantastic.
Test #4:
score: 0
Accepted
time: 1ms
memory: 5372kb
input:
4
output:
1 2 3 4 1 2 4 3 2 1 4 3 2 1 3 4 2 3 1 4 2 3 4 1 2 4 3 1 2 4 1 3 4 2 1 3 4 2 3 1 4 3 2 1 3 4 1 2 3 4 2 1 4 3 1 2 4 1 3 2 4 1 2 3 1 4 2 3 1 4 3 2 1 3 4 2 3 1 4 2 1 3 2 4 3 1 2 4 3 2 1 4 3 2 4 1
result:
ok Thank you for your great code. It was fantastic.
Test #5:
score: 0
Accepted
time: 1ms
memory: 5564kb
input:
5
output:
1 2 3 4 5 1 2 4 3 5 1 4 2 5 3 1 4 5 2 3 4 1 5 3 2 4 1 5 2 3 4 5 1 2 3 4 5 1 3 2 5 4 1 3 2 4 5 3 1 2 4 5 3 2 1 5 4 3 1 2 5 4 3 2 1 5 3 4 1 2 5 3 4 2 1 3 5 4 1 2 3 4 5 2 1 3 5 4 2 1 3 4 5 1 2 3 4 1 5 2 4 3 1 2 5 3 4 2 1 5 3 4 1 2 5 4 3 1 5 2 4 3 5 1 2 4 3 5 2 1 3 4 2 5 1 4 3...
result:
ok Thank you for your great code. It was fantastic.
Test #6:
score: 0
Accepted
time: 15ms
memory: 5792kb
input:
6
output:
1 2 3 4 5 6 2 1 3 5 4 6 1 2 5 3 6 4 2 1 3 5 6 4 1 2 3 5 4 6 2 1 5 3 6 4 1 2 5 3 4 6 1 2 3 5 6 4 2 1 5 3 4 6 1 2 5 4 3 6 2 1 4 5 6 3 1 2 4 5 3 6 2 1 5 4 3 6 2 1 4 5 3 6 1 2 5 4 6 3 1 2 4 5 6 3 2 1 5 4 6 3 1 2 5 6 4 3 1 5 2 4 6 3 1 5 2 4 3 6 5 1 4 2 3 6 5 1 2 4 3 6 1 5 2 3 4 6 1...
result:
ok Thank you for your great code. It was fantastic.
Test #7:
score: 0
Accepted
time: 59ms
memory: 7680kb
input:
7
output:
1 2 3 4 5 6 7 1 2 3 5 4 6 7 1 2 5 3 4 6 7 1 2 3 5 4 7 6 1 2 5 3 4 7 6 2 1 3 5 4 6 7 2 1 3 4 5 6 7 2 1 3 5 4 7 6 2 1 5 3 4 6 7 2 1 5 3 4 7 6 1 2 3 5 7 4 6 2 1 5 3 7 4 6 2 1 3 5 7 4 6 2 1 5 3 7 6 4 1 2 5 3 7 4 6 1 2 3 5 7 6 4 2 1 3 5 7 6 4 1 2 3 7 5 6 4 2 1 3 7 5 6 4 2 1 3 7 5 4 6 ...
result:
ok Thank you for your great code. It was fantastic.
Test #8:
score: -100
Time Limit Exceeded
input:
8