QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107756#5380. Bell RingingPetroTarnavskyi#AC ✓420ms36872kbC++171.6kb2023-05-22 18:52:022023-05-22 18:52:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-22 18:52:03]
  • 评测
  • 测评结果:AC
  • 用时:420ms
  • 内存:36872kb
  • [2023-05-22 18:52:02]
  • 提交

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(40);
	
	int n;
	cin >> n;
	
	if (n == 8) md = 12;

	VI v(n);
	iota(ALL(v), 1);
	vector<VI> p;
	map<VI, int> mapka;
	do
	{
		mapka[v] = SZ(p);
		p.PB(v);
	}while(next_permutation(ALL(v)));
	FOR(i, 0, SZ(p))
	{
		FOR (mask, 1, 1 << (n - 1))
		{
			bool bad = false;
			FOR (j, 0, n - 2)
				if (((mask >> j) & 3) == 3)
					bad = true;
			if (bad) continue;
			VI p2 = p[i];
			FOR(j, 0, n - 1)
				if (mask & (1 << j))
					swap(p2[j], p2[j + 1]);
	
			int j = mapka[p2];
			g[i].PB(j);
			deg[i]++;
		}
	}
	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;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5608kb

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: 5456kb

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: 1ms
memory: 5592kb

input:

1

output:

1 

result:

ok Thank you for your great code. It was fantastic.

Test #4:

score: 0
Accepted
time: 3ms
memory: 5460kb

input:

4

output:

1 2 3 4 
1 2 4 3 
1 4 2 3 
1 4 3 2 
4 1 2 3 
4 1 3 2 
4 3 1 2 
3 4 1 2 
3 1 4 2 
1 3 4 2 
1 3 2 4 
3 1 2 4 
3 2 1 4 
2 3 4 1 
2 4 3 1 
4 2 1 3 
2 4 1 3 
4 2 3 1 
4 3 2 1 
3 4 2 1 
3 2 4 1 
2 3 1 4 
2 1 3 4 
2 1 4 3 

result:

ok Thank you for your great code. It was fantastic.

Test #5:

score: 0
Accepted
time: 0ms
memory: 5500kb

input:

5

output:

1 2 3 4 5 
1 3 2 4 5 
1 3 4 2 5 
1 4 3 2 5 
1 4 3 5 2 
4 1 3 5 2 
4 1 5 3 2 
1 4 5 3 2 
1 5 4 3 2 
1 4 5 2 3 
4 1 5 2 3 
4 1 2 5 3 
1 4 2 3 5 
4 1 3 2 5 
4 3 1 5 2 
4 3 1 2 5 
3 4 1 2 5 
3 1 4 2 5 
1 3 4 5 2 
1 3 5 4 2 
3 1 4 5 2 
3 4 1 5 2 
3 4 5 1 2 
4 3 5 1 2 
4 3 5 2 1 
4 5 3 1 2 
5 4 1 3 2 
5 1...

result:

ok Thank you for your great code. It was fantastic.

Test #6:

score: 0
Accepted
time: 8ms
memory: 5932kb

input:

6

output:

1 2 3 4 5 6 
1 3 2 4 6 5 
1 2 3 4 6 5 
1 2 4 3 6 5 
1 2 4 3 5 6 
2 1 3 4 6 5 
1 2 3 6 4 5 
1 2 6 3 4 5 
1 6 2 3 4 5 
6 1 2 3 4 5 
6 1 3 2 4 5 
1 6 2 3 5 4 
1 2 6 3 5 4 
1 6 2 5 3 4 
6 1 2 5 3 4 
6 1 2 3 5 4 
1 6 3 2 5 4 
1 6 3 2 4 5 
6 1 3 2 5 4 
6 3 1 2 5 4 
6 3 2 1 5 4 
6 3 1 2 4 5 
6 1 3 4 2 5 
6...

result:

ok Thank you for your great code. It was fantastic.

Test #7:

score: 0
Accepted
time: 61ms
memory: 8420kb

input:

7

output:

1 2 3 4 5 6 7 
1 2 3 4 5 7 6 
2 1 3 5 4 7 6 
2 1 3 4 5 6 7 
1 2 3 5 4 6 7 
2 1 3 4 5 7 6 
1 2 4 3 5 7 6 
2 1 4 3 5 7 6 
1 2 4 3 5 6 7 
2 1 4 3 5 6 7 
2 1 4 5 3 6 7 
1 2 4 5 3 7 6 
2 1 4 5 3 7 6 
1 2 4 5 3 6 7 
1 4 2 5 3 7 6 
1 4 2 3 5 6 7 
1 4 2 5 3 6 7 
4 1 2 3 5 6 7 
1 4 2 3 5 7 6 
4 1 2 5 3 7 6 
...

result:

ok Thank you for your great code. It was fantastic.

Test #8:

score: 0
Accepted
time: 420ms
memory: 36872kb

input:

8

output:

1 2 3 4 5 6 7 8 
1 2 3 5 4 6 8 7 
1 2 3 4 5 6 8 7 
1 2 3 4 5 8 6 7 
1 3 2 4 5 6 8 7 
1 3 2 5 4 6 7 8 
1 3 2 4 5 6 7 8 
1 3 2 5 4 7 6 8 
1 2 3 5 4 6 7 8 
2 1 3 5 4 6 7 8 
1 2 3 5 4 7 6 8 
1 2 3 4 5 7 6 8 
1 2 3 5 4 7 8 6 
1 2 3 4 5 7 8 6 
1 3 2 4 5 7 6 8 
1 3 2 5 4 7 8 6 
1 3 2 4 5 7 8 6 
1 2 3 4 5 8...

result:

ok Thank you for your great code. It was fantastic.