# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
149973 | 2019-09-01T07:29:12 Z | 코딩은 체육과목입니다(#3561, jwvg0425, 16silver, jhuni) | On the Grid (FXCUP4_grid) | C++17 | 0 ms | 0 KB |
#include "grid.h" #include <random> using namespace std; int n; vector<int> ans; vector<int> idx; int get_max_disk(int x) { vector<int> v; std::random_device rd; std::mt19937 g(rd()); vector<bool> vis(n, true); for(int i=0;i<n;i++){ if (!ans[i]){ v.push_back(i); } else { vis[i] = false; } } int p = x; int cnt = 0; while(p){ cnt++; p>>=1; } for(int i=0;i<cnt;i++){ shuffle(v.begin(), v.end(), g); vector<int> t = v; for(int j=x+1; j<=n; j++){ t.push_back(idx[j]); } int r = PutDisks(t); r -= (n-x); r -= x - 1; for(int j=0;j<x-r;j++){ vis[v[j]] = false; } } for(int i=0;i<n;i++){ if (vis[i]){ vector<int> v; v.push_back(i); for(int j=0;j<n;j++){ if (!ans[j] && j != i){ v.push_back(j); } } for(int j=x+1;j<=n;j++){ v.push_back(idx[j]); } int r = PutDisks(v); if (r - (n-x) == 2*x-1) { return i; } } } return -1; } std::vector<int> SortDisks(int N) { n = N; ans.resize(n); idx.resize(n+1); for(int i=n;i>=1;i--){ int x = get_max_disk(i); ans[x] = i; idx[i] = x; } return ans; }