Submission #970442

#TimeUsernameProblemLanguageResultExecution timeMemory
970442NotLinuxThe Collection Game (BOI21_swaps)C++17
5 / 100
46 ms2072 KiB
//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
//     swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include <bits/stdc++.h>
#include "swaps.h"
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
void solve(int N , int V) {
	vector < int > v(N),ans;
	iota(all(v),1);
	map < pair < int , int > , bool > memo;
	while(sz(v)){
		vector < int > curv = v , newv;
		while(sz(curv) > 1){
			newv.clear();
			vector < int > with_schedule , with_memo;
			for(int i = 0;i<(sz(curv)-1);i+=2){
				if(memo.count({curv[i] , curv[i+1]})){
					with_memo.push_back(i);
				}
				else {
					with_schedule.push_back(i);
					schedule(curv[i] , curv[i+1]);
				}
			}
			vector < int > res = visit();
			for(auto itr : with_memo){
				newv.push_back(curv[itr + memo[{curv[itr] , curv[itr+1]}]]);
			}			
			for(int i = 0;i<sz(res);i++){
				newv.push_back(curv[with_schedule[i] + res[i]]);
				memo[{curv[with_schedule[i]] , curv[with_schedule[i] + 1]}] = res[i];
			}
			if(sz(curv) & 1){
				newv.push_back(curv.back());
			}
			curv = newv;
			// cout << "	curv : ";for(auto itr : curv)cout << itr << " ";cout << endl;
		}
		ans.push_back(curv[0]);
		v.erase(find(all(v) , curv[0]));
		// cout << "v : ";for(auto itr : v)cout << itr << " ";cout << endl;
		// cout << "ans : ";for(auto itr : ans)cout << itr << " ";cout << endl;
		// cout << endl;
	}
	reverse(all(ans));
	answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...