제출 #1301916

#제출 시각아이디문제언어결과실행 시간메모리
1301916BzslayedJob Scheduling (CEOI12_jobs)C++20
100 / 100
259 ms30552 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ll long long #define ull unsigned long long #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define coutpair(p) cout << p.first << " " << p.second << "|" template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const ll INF = 1e15; vector<ll> v[100005]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, d, m; cin >> n >> d >> m; pll jb[m]; for (int i=0; i<m; i++) cin >> jb[i].first, jb[i].second = i+1; sort(jb, jb+m); ll lo = 1, hi = 1e9, ans = INF; stack<pll> s; while (lo <= hi){ ll x = (lo+hi)/2; while (!s.empty()) s.pop(); for (int i=n; i>=1; i--) s.push({i, x}); bool pos = true; for (int i=0; i<m; i++){ ll tar = jb[i].first+d; if (tar < s.top().first || s.empty()){ pos = false; break; } while (jb[i].first > s.top().first) s.pop(); s.top().second--; if (s.top().second == 0) s.pop(); } if (pos) hi = x-1, ans = min(ans, x); else lo = x+1; } while (!s.empty()) s.pop(); for (int i=n; i>=1; i--) s.push({i, ans}); for (int i=0; i<m; i++){ auto [day, id] = jb[i]; while (day > s.top().first) s.pop(); v[s.top().first].push_back(id); s.top().second--; if (s.top().second == 0) s.pop(); } cout << ans << "\n"; for (int i=1; i<=n; i++){ if (v[i].empty()) cout << 0 << "\n"; else{ for (auto it : v[i]) cout << it << " "; cout << 0 << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...