답안 #711372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711372 2023-03-16T18:13:39 Z asteilind Job Scheduling (CEOI12_jobs) C++17
100 / 100
852 ms 31880 KB
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <set>
#include <numeric>
#include <bitset>
#include <climits>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
//#define MOD 1000000007
using namespace std;
void setIO(string name = "") { // name is nonempty for USACO file I/O
    ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
    if(name.length()){
        freopen((name+".in").c_str(), "r", stdin); // see Input & Output
        freopen((name+".out").c_str(), "w", stdout);
    }
}
void solve()
{
    int N,D,M; cin >> N >> D >> M;
    map<int,vector<int>> job;
    int maxv = 0;
    forn(i,M)
    {
        int day; cin >> day;
        job[day].push_back(i+1);
        maxv = max((int)job[day].size(),maxv);
        
    }
    int i=0;
    int j=maxv;
    vector<vector<int>> ans(N);
    int min_machine = 1e9;
    while (i <= j)
    {
        int mid = (i+j)/2;
        vector<vector<int>> temp(N);
        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
        bool flag = true;
        for (int day=1; N>=day ; day++)
        {
            for (auto x: job[day])
            {
                pq.push({day+D,x});
            }
            for (int a=0; mid>a && !pq.empty(); a++)
            {
                auto [dy,indx] = pq.top();
                temp[day-1].push_back(indx);
                pq.pop();
            }
            if (!pq.empty() && pq.top().first <= day)
            {
                flag = false;
                break;
            }
        }
        if (flag && pq.empty())
        {
            min_machine = mid;
            j = mid-1;
            ans = temp;
        }
        else i = mid+1;
    }
    cout << min_machine << endl;
    for (int i=0 ; N>i ; i++)
    {
        for (int j=0; ans[i].size()>j ; j++)
        {
            cout << ans[i][j] << ' ';
        }
        cout << 0 << endl;
    }
}
int main()
{
    setIO("");
    solve();
}

Compilation message

jobs.cpp: In function 'void solve()':
jobs.cpp:78:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |         for (int j=0; ans[i].size()>j ; j++)
      |                       ~~~~~~~~~~~~~^~
jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name+".in").c_str(), "r", stdin); // see Input & Output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 4676 KB Output is correct
2 Correct 175 ms 4712 KB Output is correct
3 Correct 184 ms 4676 KB Output is correct
4 Correct 181 ms 4764 KB Output is correct
5 Correct 174 ms 4788 KB Output is correct
6 Correct 174 ms 4676 KB Output is correct
7 Correct 172 ms 4764 KB Output is correct
8 Correct 171 ms 4688 KB Output is correct
9 Correct 249 ms 15300 KB Output is correct
10 Correct 298 ms 15464 KB Output is correct
11 Correct 49 ms 2456 KB Output is correct
12 Correct 179 ms 4752 KB Output is correct
13 Correct 182 ms 7920 KB Output is correct
14 Correct 388 ms 12128 KB Output is correct
15 Correct 246 ms 10684 KB Output is correct
16 Correct 366 ms 15708 KB Output is correct
17 Correct 532 ms 20376 KB Output is correct
18 Correct 731 ms 19244 KB Output is correct
19 Correct 852 ms 31880 KB Output is correct
20 Correct 531 ms 20372 KB Output is correct