Submission #972163

#TimeUsernameProblemLanguageResultExecution timeMemory
972163hotboy2703Super Dango Maker (JOI22_dango3)C++17
22 / 100
9115 ms1416 KiB
#include "dango3.h" #include <bits/stdc++.h> using ll = int; using namespace std; #define pll pair <ll,ll> #define fi first #define se second #define MP make_pair #define BIT(mask,i) (((mask) >> (i))&1LL) #define MASK(i) (1LL<<(i)) #define sz(a) (ll((a).size())) namespace { vector <ll> color[401]; mt19937_64 rng(69420); } void Solve(int n,int m) { vector <ll> a(n*m); iota(a.begin(),a.end(),1); shuffle(a.begin(),a.end(),rng); ll rem = m; set <ll> lft; for (ll i = 1;i <= n * m;i ++)lft.insert(i); auto alldif = [&](vector <ll> x) -> bool{ if (sz(x) < 2)return 1; for (auto y:x)lft.erase(y); vector <ll> tmp(lft.begin(),lft.end()); for (auto y:x)lft.insert(y); return (Query(tmp) == rem - 1); }; for (ll i = 0;i < n * m;i ++){ ll id = a[i]; vector <ll> x; for (ll j = 1;j <= n;j ++){ if (sz(color[j]))x.push_back(color[j][0]); } x.push_back(id); if (sz(x) <= n && alldif(x)){ for (ll j = 1;j <= n;j ++){ if (!sz(color[j])){color[j].push_back(id);break;} } } else{ x.pop_back(); ll l = 0; ll r = sz(x) - 1; ll found = -1; while (l <= r){ ll mid = (l + r) >> 1; vector <ll> tmp; for (ll i = 0;i <= mid;i ++)tmp.push_back(x[i]); tmp.push_back(id); if (alldif(tmp)){ l = mid + 1; } else{ found = x[mid]; r = mid - 1; } } for (ll j = 1;j <= n;j ++){ if (sz(color[j]) && color[j][0] == found){color[j].push_back(id);break;} } } ll cnt = 0; for (ll j = 1;j <= n;j ++){ if (sz(color[j]))cnt++; } if (cnt == n){ vector <ll> ans; for (ll j = 1;j <= n;j ++){ ans.push_back(color[j].back()); color[j].pop_back(); } Answer(ans); for (auto x:ans)lft.erase(x); rem--; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...