QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64195#91. Secret Permutationxiaoyaowudi0 2ms3528kbC++202.1kb2022-11-24 11:35:302022-11-24 11:35:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 11:35:33]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3528kb
  • [2022-11-24 11:35:30]
  • 提交

answer

#include "permutation.h"
#include <cmath>
#include <random>
#include <vector>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <iostream>
constexpr int NN(310);
int idx[NN],res[NN],perm[NN],ci[NN],cval,sub[NN];bool vis[NN<<1];
bool check(int n)
{
	int tot(0);
	for(int i(2);i<=n;++i) tot+=std::abs(perm[ci[i]]-perm[ci[i-1]]);
	return tot==cval;
}
bool dfs(int k,int n,int mx=0,int mn=0)
{
	if(k==n+1)
	{
		return check(n);
	}
	{
		int nw(perm[idx[k-1]]+res[k]);
		if(std::max(nw,mx)-std::min(mn,nw)<n && !vis[NN+nw])
		{
			vis[(perm[idx[k]]=nw)+NN]=true;
			bool cap(dfs(k+1,n,std::max(nw,mx),std::min(mn,nw)));
			if(cap) return true;
			vis[nw+NN]=false;
		}
	}
	{
		int nw(perm[idx[k-1]]-res[k]);
		if(std::max(nw,mx)-std::min(mn,nw)<n && !vis[NN+nw])
		{
			vis[(perm[idx[k]]=nw)+NN]=true;
			bool cap(dfs(k+1,n,std::max(nw,mx),std::min(mn,nw)));
			if(cap) return true;
			vis[nw+NN]=false;
		}
	}
	return false;
}
void solve(int N)
{
	int n(N);
	std::iota(idx+1,idx+n+1,1);
	std::iota(ci+1,ci+n+1,1);
	// int seed;
	// std::cin>>seed;
	// std::mt19937 rnd(seed);
	// std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
	std::mt19937 rnd(40);
	std::shuffle(idx+1,idx+n+1,rnd);
	std::shuffle(ci+1,ci+n+1,rnd);
	cval=query(std::vector<int>(ci+1,ci+n+1));
	// for(int i(1);i<=n;++i) std::cerr<<idx[i]<<" ";
	// std::cerr<<std::endl;
	for(int i(2);i<=n;++i)
	{
		std::rotate(idx+1,idx+2,idx+n+1);
		sub[i]=query(std::vector<int>(idx+1,idx+n+1));
	}
	std::rotate(idx+1,idx+2,idx+n+1);
	// for(int i(1);i<=n;++i) std::cerr<<idx[i]<<" ";
	// std::cerr<<std::endl;
	int mns(*std::min_element(sub+2,sub+n+1)),mxs(*std::max_element(sub+2,sub+n+1));
	for(int T(mxs+1);T<mns+n;++T)
	{
		for(int i(2);i<=n;++i) res[i]=T-sub[i];
		perm[idx[1]]=0;
		vis[NN]=true;
		bool res(dfs(2,n));
		if(res)
		{
			int mn(*std::min_element(perm+1,perm+n+1));
			for(int i(1);i<=n;++i) perm[i]=perm[i]-mn+1/*,std::cerr<<perm[i]<<" ";std::cerr<<std::endl*/;
			answer(std::vector<int>(perm+1,perm+n+1));
			return;
		}
	}
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 15
Accepted
time: 2ms
memory: 3528kb

input:

7
5 7 1 3 2 4 6

output:

0 7 1050790

result:

points 1.0 7 steps

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 3436kb

input:

4
3 4 2 1

output:

-1

result:

wrong answer Your answer is not correct.

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%