제출 #1308250

#제출 시각아이디문제언어결과실행 시간메모리
1308250joze_plocnikJob Scheduling (CEOI12_jobs)C++20
40 / 100
478 ms87700 KiB
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> #include <sstream> #include <map> #include <cstdio> #include <queue> #include <cmath> #include <stack> #include <cctype> // doda isupper #define int long long // vse ti je long long #define vi vector<int> #define vpii vector<pair<int,int>> #define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false); #define forn(i,n) for(int i = 0; i<n; i++) #define forn1(i,n) for(int i = 1; i<=n; i++) #define all(x) (x).begin(), (x).end() #define pi pair<int,int> #define vvi vector<vi> #define vvc vector<vector<char>> #define sz(x) (x).size() #define pb push_back #define str string using namespace std; signed main() { int n,d,m; cin >> n >> d>>m; map<int,int> naroceni; //vector<vector<int>> ans(n); //za vsako vrstico posebej //vector<vector<int>> anspravi(n); vector<queue<int>> id(n-d); forn(i,m){ int t; cin >> t; naroceni[--t]++; id[t].push(i+1); } int l = 1, r= 1e6; while(l<r){ int rob = (l+r)/2; //cout << "rob: " << rob << "\n"; priority_queue<pair<int,int>, vpii, greater<pair<int,int>>> cakajoci; // prvo je od kdaj, drugo je koliko jih je //vector<queue<int>> ids = id; bool vredu = true; forn(i,n){ //cout << "smo na indexu: " << i <<"\n"; int mesta = rob; while(!cakajoci.empty() && mesta > 0){ pair<int,int> vrh = cakajoci.top(); cakajoci.pop(); int cng = min(mesta,vrh.second); vrh.second -= cng; mesta -= cng; //forn(_,cng){ // int ven = ids[vrh.first].front(); ids[vrh.first].pop(); // ans[i].push_back(ven); //} if(vrh.second != 0) cakajoci.push(vrh); //tu smo jih reciklirali else { //enega smo izpraznili, preverimo, če smo to storili dovolj hitro if(i - vrh.first > d) vredu = false; } } int recikl = max(0LL,naroceni[i]-mesta); if(recikl > 0) cakajoci.push({i,recikl}); // zdaj pa obdelamo trenutno //int novi = naroceni[i]; /* while(mesta > 0 && novi > 0){ //int ven = ids[i].front(); ids[i].pop(); //ans[i].push_back(ven); //cout << ven << " "; novi--; mesta--; }*/ //if(novi) cakajoci.push({i,novi}); } //cout <<"stvar je: " << vredu << "\n"; if(vredu){ r = rob; } else { l = rob+1; } } cout << l << "\n"; /* forn(i,n){ int siz = sz(anspravi[i]); cout <<"siz je: " << siz << "\n"; forn(j, siz){ cout << anspravi[i][j] << " "; } cout << "0\n"; }*/ // zdaj pa isto, samo da pišemo rešitev za sabo int rob = l; //cout << "rob: " << rob << "\n"; priority_queue<pair<int,int>, vpii, greater<pair<int,int>>> cakajoci; // prvo je od kdaj, drugo je koliko jih je bool vredu = true; forn(i,n){ //cout << "smo na indexu: " << i <<"\n"; int mesta = rob; while(!cakajoci.empty() && mesta > 0){ pair<int,int> vrh = cakajoci.top(); cakajoci.pop(); int cng = min(mesta,vrh.second); vrh.second -= cng; mesta -= cng; forn(_,cng){ int ven = id[vrh.first].front(); id[vrh.first].pop(); //ans[i].push_back(ven); cout << ven << " "; } if(vrh.second != 0) cakajoci.push(vrh); //tu smo jih reciklirali else { //enega smo izpraznili, preverimo, če smo to storili dovolj hitro if(i - vrh.first > d) vredu = false; } } //int recikl = max(0LL,naroceni[i]-mesta); //if(recikl > 0) cakajoci.push({i,recikl}); // zdaj pa obdelamo trenutno int novi = naroceni[i]; while(mesta > 0 && novi > 0){ int ven = id[i].front(); id[i].pop(); //ans[i].push_back(ven); cout << ven << " "; novi--; mesta--; } if(novi) cakajoci.push({i,novi}); cout << "0\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...