Submission #702415

# Submission time Handle Problem Language Result Execution time Memory
702415 2023-02-24T02:35:32 Z jamezzz The Collection Game (BOI21_swaps) C++17
100 / 100
6 ms 336 KB
#include "swaps.h"
#include <bits/stdc++.h>
using namespace std;

bool in[1005];
vector<int> v;
vector<pair<int,int>> asks;

void compute(){
	auto res=visit();
	reverse(res.begin(),res.end());
	for(auto[a,b]:asks){
		if(res.back()==0)swap(v[a],v[b]);
		res.pop_back();
		in[v[a]]=in[v[b]]=false;
	}
	asks.clear();
}

void solve(int N,int V){
	for(int i=1;i<=N;++i){
		v.push_back(i);
	}
	for(int p=1;p<=N;p<<=1){
		for(int k=p;k>=1;k>>=1){
			for(int j=k%p;j<=N-1-k;j+=2*k){
				for(int i=0;i<=k-1;++i){
					if((i+j)/(2*p)==(i+j+k)/(2*p)&&i+j+k<N){
						if(in[v[i+j]]||in[v[i+j+k]])compute();
						schedule(v[i+j],v[i+j+k]);
						in[v[i+j]]=in[v[i+j+k]]=true;
						asks.push_back({i+j,i+j+k});
					}
				}
			}
		}
	}
	if(!asks.empty())compute();
	answer(v);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 312 KB Correct
5 Correct 4 ms 308 KB Correct
6 Correct 4 ms 316 KB Correct
7 Correct 4 ms 312 KB Correct
8 Correct 5 ms 312 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 300 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 328 KB Correct
5 Correct 4 ms 316 KB Correct
6 Correct 4 ms 308 KB Correct
7 Correct 4 ms 312 KB Correct
8 Correct 4 ms 312 KB Correct
9 Correct 4 ms 332 KB Correct
10 Correct 6 ms 312 KB Correct
11 Correct 4 ms 308 KB Correct
12 Correct 4 ms 308 KB Correct
13 Correct 5 ms 316 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 1 ms 208 KB Correct
4 Correct 2 ms 208 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 288 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 288 KB Correct
5 Correct 1 ms 252 KB Correct
6 Correct 1 ms 208 KB Correct
7 Correct 2 ms 208 KB Correct
8 Correct 4 ms 300 KB Correct
9 Correct 4 ms 316 KB Correct
10 Correct 4 ms 320 KB Correct
11 Correct 4 ms 316 KB Correct
12 Correct 4 ms 316 KB Correct
13 Correct 0 ms 208 KB Correct
14 Correct 1 ms 208 KB Correct
15 Correct 2 ms 208 KB Correct
16 Correct 4 ms 312 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 5 ms 308 KB Correct
5 Correct 4 ms 328 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 2 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 5 ms 308 KB Correct
5 Correct 4 ms 328 KB Correct
6 Correct 1 ms 208 KB Correct
7 Correct 1 ms 208 KB Correct
8 Correct 2 ms 208 KB Correct
9 Correct 4 ms 308 KB Correct
10 Correct 4 ms 320 KB Correct
11 Correct 4 ms 312 KB Correct
12 Correct 4 ms 312 KB Correct
13 Correct 4 ms 312 KB Correct
14 Correct 5 ms 312 KB Correct
15 Correct 3 ms 336 KB Correct
16 Correct 4 ms 312 KB Correct
17 Correct 5 ms 308 KB Correct
18 Correct 5 ms 312 KB Correct
19 Correct 1 ms 208 KB Correct
20 Correct 1 ms 208 KB Correct
21 Correct 2 ms 208 KB Correct
22 Correct 4 ms 312 KB Correct
23 Correct 4 ms 296 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 312 KB Correct
5 Correct 4 ms 272 KB Correct
6 Correct 4 ms 284 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 4 ms 312 KB Correct
5 Correct 4 ms 272 KB Correct
6 Correct 4 ms 284 KB Correct
7 Correct 0 ms 208 KB Correct
8 Correct 1 ms 208 KB Correct
9 Correct 2 ms 208 KB Correct
10 Correct 4 ms 312 KB Correct
11 Correct 4 ms 312 KB Correct
12 Correct 4 ms 312 KB Correct
13 Correct 4 ms 316 KB Correct
14 Correct 4 ms 316 KB Correct
15 Correct 4 ms 316 KB Correct
16 Correct 4 ms 316 KB Correct
17 Correct 4 ms 316 KB Correct
18 Correct 4 ms 308 KB Correct
19 Correct 4 ms 312 KB Correct
20 Correct 0 ms 208 KB Correct
21 Correct 1 ms 208 KB Correct
22 Correct 3 ms 208 KB Correct
23 Correct 5 ms 288 KB Correct
24 Correct 4 ms 292 KB Correct
25 Correct 4 ms 284 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 6 ms 312 KB Correct
5 Correct 4 ms 304 KB Correct
6 Correct 4 ms 284 KB Correct
7 Correct 4 ms 280 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Correct
2 Correct 1 ms 208 KB Correct
3 Correct 2 ms 208 KB Correct
4 Correct 6 ms 312 KB Correct
5 Correct 4 ms 304 KB Correct
6 Correct 4 ms 284 KB Correct
7 Correct 4 ms 280 KB Correct
8 Correct 0 ms 208 KB Correct
9 Correct 1 ms 208 KB Correct
10 Correct 1 ms 304 KB Correct
11 Correct 2 ms 208 KB Correct
12 Correct 4 ms 316 KB Correct
13 Correct 5 ms 316 KB Correct
14 Correct 4 ms 316 KB Correct
15 Correct 5 ms 312 KB Correct
16 Correct 5 ms 312 KB Correct
17 Correct 4 ms 312 KB Correct
18 Correct 4 ms 312 KB Correct
19 Correct 4 ms 312 KB Correct
20 Correct 4 ms 308 KB Correct
21 Correct 4 ms 316 KB Correct
22 Correct 1 ms 208 KB Correct
23 Correct 1 ms 288 KB Correct
24 Correct 2 ms 292 KB Correct
25 Correct 4 ms 308 KB Correct
26 Correct 4 ms 296 KB Correct
27 Correct 4 ms 292 KB Correct
28 Correct 4 ms 288 KB Correct