제출 #1227880

#제출 시각아이디문제언어결과실행 시간메모리
1227880jasonicMonster Game (JOI21_monster)C++20
0 / 100
3 ms432 KiB
#include "monster.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define fastIO cin.tie(0); ios::sync_with_stdio(false) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> dnc(vector<int> idcs, int l, int r) { if(idcs.size() == 1) return idcs; if(l == r) return idcs; if(l == r+1) { if(! Query(idcs[0], idcs[1])) { // 0 is less than swap(idcs[0], idcs[1]); } return idcs; } int rand = rng(); int pivot = abs(rand)%idcs.size(); vector<int> la, ra; for(int i = 0; i < idcs.size(); i++) { if(i == pivot) continue; if(Query(idcs[pivot], idcs[i])) { la.push_back(idcs[i]); } else ra.push_back(idcs[i]); } // cout << idcs[pivot] << '\n'; // for(auto &i : la) cout << i << ' '; cout << '\n'; // for(auto &i : ra) cout << i << ' '; cout << '\n'; la = dnc(la, l, l+la.size()-1); ra = dnc(ra, l+la.size()+1, r); vector<int> ans; // case 1, we dont break if(min(la.size(), ra.size()) != 1) { ans.insert(ans.end(), la.begin(), la.end()); ans.push_back(idcs[pivot]); ans.insert(ans.end(), ra.begin(), ra.end()); swap(ans[la.size()-1], ans[la.size()+1]); } else { // case 2.1 we are on the edge if(la.size() == 1) { if(Query(la[0], ra[0])) { // the pivot is the smallest ans.push_back(idcs[pivot]); ans.push_back(la[0]); ans.insert(ans.end(), ra.begin(), ra.end()); } else { ans.insert(ans.end(), la.begin(), la.end()); ans.push_back(idcs[pivot]); ans.insert(ans.end(), ra.begin(), ra.end()); swap(ans[la.size()-1], ans[la.size()+1]); } } else { if(Query(ra[0], la[la.size()-1])) { // the pivot is the biggest ans.insert(ans.end(), la.begin(), la.end()); ans.push_back(ra[0]); ans.push_back(idcs[pivot]); } else { ans.insert(ans.end(), la.begin(), la.end()); ans.push_back(idcs[pivot]); ans.insert(ans.end(), ra.begin(), ra.end()); swap(ans[la.size()-1], ans[la.size()+1]); } } } return ans; } vector<int> Solve(int n) { vector<int> arr; for(int i = 0; i < n; i++) arr.push_back(i); vector<int> ans1 = dnc(arr, 0, n-1); vector<int> ans2(n); for(int i = 0; i < n; i++) ans2[ans1[i]] = i; return ans2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...