QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64197#91. Secret Permutationxiaoyaowudi50 73ms3716kbC++202.6kb2022-11-24 11:41:092022-11-24 11:41:10

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:41:10]
  • 评测
  • 测评结果:50
  • 用时:73ms
  • 内存:3716kb
  • [2022-11-24 11:41:09]
  • 提交

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)
{
	if(n<=7) return std::abs(perm[idx[n]]-perm[idx[1]])==res[1];
	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);
	if(n<=7)
	{
		int tot(0);
		for(int i(1);i<=n;++i)
		{
			sub[i]=query(std::vector<int>(idx+1,idx+n+1));
			std::rotate(idx+1,idx+2,idx+n+1);
			tot+=sub[i];
		}
		tot/=(n-1);
		for(int i(1);i<=n;++i) res[i]=tot-sub[i];
		dfs(2,n);
		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;
	}
	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<<ci[i]<<" ";
	// std::cerr<<cval<<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;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 15
Accepted

Test #1:

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

input:

7
5 7 1 3 2 4 6

output:

0 7 1050790

result:

points 1.0 7 steps

Test #2:

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

input:

4
3 4 2 1

output:

0 4 0

result:

points 1.0 4 steps

Test #3:

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

input:

6
3 5 4 2 6 1

output:

0 6 0

result:

points 1.0 6 steps

Test #4:

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

input:

7
5 7 2 6 4 3 1

output:

0 7 0

result:

points 1.0 7 steps

Test #5:

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

input:

7
7 4 6 2 1 3 5

output:

0 7 9010

result:

points 1.0 7 steps

Test #6:

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

input:

7
1 2 6 5 4 7 3

output:

0 7 11756225322523

result:

points 1.0 7 steps

Subtask #2:

score: 35
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 35
Accepted
time: 2ms
memory: 3456kb

input:

50
33 8 50 28 6 40 15 17 22 11 30 32 23 10 27 48 13 16 29 24 43 44 9 45 47 4 5 25 42 41 2 14 21 35 19 12 7 36 1 46 26 3 49 34 18 20 37 31 38 39

output:

0 50 11685440196884524

result:

points 1.0 50 steps

Test #8:

score: 35
Accepted
time: 2ms
memory: 3512kb

input:

50
36 39 40 31 28 48 24 20 35 25 26 19 9 23 34 49 6 33 21 32 10 7 16 37 5 45 3 15 27 17 22 47 30 29 12 38 42 46 8 18 11 50 41 4 1 13 43 44 2 14

output:

0 50 15214

result:

points 1.0 50 steps

Test #9:

score: 35
Accepted
time: 2ms
memory: 3716kb

input:

46
28 27 22 38 31 20 18 16 3 25 8 29 4 34 23 33 36 10 12 24 30 40 7 17 6 13 39 26 9 32 21 19 42 44 41 5 14 15 35 11 37 46 45 1 2 43

output:

0 46 393

result:

points 1.0 46 steps

Test #10:

score: 35
Accepted
time: 2ms
memory: 3456kb

input:

50
16 26 25 42 9 49 18 33 31 12 15 37 3 38 45 10 22 19 14 39 8 32 28 30 1 46 20 5 2 21 41 50 40 11 36 4 29 43 23 17 13 44 47 27 48 24 35 7 34 6

output:

0 50 6567

result:

points 1.0 50 steps

Test #11:

score: 35
Accepted
time: 2ms
memory: 3452kb

input:

42
21 9 33 35 4 32 8 34 20 39 25 10 17 11 41 18 2 29 27 38 22 16 15 13 1 5 26 23 36 42 30 19 24 40 37 6 12 28 31 14 7 3

output:

0 42 2859113345761375251

result:

points 1.0 42 steps

Test #12:

score: 35
Accepted
time: 0ms
memory: 3460kb

input:

49
11 41 33 26 3 31 34 17 1 14 13 39 48 24 12 15 21 29 18 46 20 30 35 28 44 22 45 16 25 8 49 27 10 37 43 5 9 40 6 42 38 36 2 7 23 32 4 47 19

output:

0 49 25506386

result:

points 1.0 49 steps

Test #13:

score: 35
Accepted
time: 2ms
memory: 3712kb

input:

46
40 41 17 10 27 32 14 18 7 8 38 19 12 24 44 28 16 36 29 11 35 45 42 2 4 22 46 31 20 39 26 37 9 1 5 15 23 43 33 30 25 21 34 6 13 3

output:

0 46 22808398

result:

points 1.0 46 steps

Test #14:

score: 35
Accepted
time: 2ms
memory: 3464kb

input:

50
28 26 22 1 50 34 36 45 15 8 37 33 44 27 31 16 47 25 38 21 5 23 29 39 35 3 20 42 41 13 17 49 43 24 40 2 48 14 46 11 18 9 19 32 30 12 4 10 6 7

output:

0 50 13329558

result:

points 1.0 50 steps

Test #15:

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

input:

50
33 41 38 49 34 15 36 44 28 32 20 8 18 45 26 5 21 40 17 23 27 1 46 7 42 9 47 35 13 12 16 29 2 31 22 19 10 30 39 11 43 50 25 37 4 24 3 6 48 14

output:

0 50 15214

result:

points 1.0 50 steps

Test #16:

score: 35
Accepted
time: 2ms
memory: 3472kb

input:

50
30 18 24 4 38 48 41 3 37 17 47 14 9 12 23 50 45 10 21 6 32 36 25 27 49 44 40 46 7 16 35 8 29 11 2 34 33 28 19 42 15 5 26 31 20 22 39 43 1 13

output:

0 50 7037

result:

points 1.0 50 steps

Subtask #3:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #17:

score: 50
Accepted
time: 43ms
memory: 3600kb

input:

256
60 184 194 99 230 67 22 54 231 118 124 69 41 248 254 88 66 123 180 152 256 52 56 201 160 21 74 188 165 244 97 10 179 91 176 232 42 61 228 111 83 164 182 197 134 71 100 103 252 211 222 172 240 221 250 65 174 155 26 183 77 140 92 2 154 110 198 39 129 223 234 33 116 102 9 122 53 216 203 105 148 20 ...

output:

0 256 0

result:

points 1.0 256 steps

Test #18:

score: 50
Accepted
time: 73ms
memory: 3536kb

input:

245
81 214 159 82 233 138 128 62 70 72 221 164 126 2 141 13 56 44 49 166 196 112 50 189 40 201 10 218 231 101 229 122 45 212 175 176 154 147 93 241 54 32 236 1 145 15 69 39 202 137 88 239 181 68 90 118 178 114 95 207 102 4 46 139 96 99 190 25 107 48 191 108 71 132 180 183 149 55 121 169 52 19 242 10...

output:

0 245 0

result:

points 1.0 245 steps

Test #19:

score: 50
Accepted
time: 36ms
memory: 3484kb

input:

244
142 45 111 20 44 80 168 13 202 109 224 79 218 220 165 42 99 198 18 35 48 147 68 156 102 151 60 195 106 92 197 229 51 139 242 133 34 3 30 216 91 5 209 12 171 150 132 188 231 39 50 74 67 179 72 145 88 158 98 210 16 141 28 201 167 205 23 22 164 235 204 192 181 222 117 180 200 138 214 206 61 135 149...

output:

0 244 345743

result:

points 1.0 244 steps

Test #20:

score: 50
Accepted
time: 18ms
memory: 3584kb

input:

256
174 156 208 89 4 180 248 17 217 48 211 143 25 223 102 28 230 43 18 119 232 226 86 61 1 204 129 244 130 203 162 81 177 154 6 38 134 215 126 94 194 16 42 62 27 191 219 108 196 198 73 181 14 74 12 67 137 253 117 23 151 9 60 127 206 107 239 112 212 87 235 158 95 26 147 40 46 69 152 234 121 176 52 21...

output:

0 256 63212796440

result:

points 1.0 256 steps

Test #21:

score: 0
Time Limit Exceeded

input:

249
177 173 130 231 197 42 154 175 187 68 170 240 86 204 235 27 142 61 58 138 56 148 35 135 23 5 213 121 82 216 94 48 159 117 77 53 184 239 110 34 13 21 90 211 126 218 171 10 198 206 98 132 73 96 25 95 136 43 12 248 125 45 190 24 41 166 46 40 47 169 232 99 79 217 219 246 66 71 55 229 185 220 199 164...

output:

Unauthorized output

result: