답안 #996341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996341 2024-06-10T13:24:38 Z Br3ad Job Scheduling (CEOI12_jobs) C++17
100 / 100
304 ms 26044 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PF push_front
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)

const int N = 1e6 + 5;
const int M = 1e9 + 7; 
const int inf = 0x3f3f3f3f;
const ll int INF = 1e18;

int bin(int l, int r, function<bool(int)> f){
    while(l < r){
        int mid = l + (r - l)/2;
        if(f(mid)){
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return l;
}

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    // ifstream cin();
    // ofstream cout();
    
    vector<pair<int, int>> v;
    int n, d, m, a;
    cin >> n >> d >> m;
    for(int i = 0; i < m; i++){
        cin >> a;
        v.PB(MP(a, i+1));
    }
    
    sort(v.begin(), v.end());

    vector<vector<int>> ans;
    int mac = bin(1, m, [&](int x){
        vector<vector<int>> cur_ans;
        bool valid = true;
        int tot = 0;
        for(int day = 1, i = 0; day <= n && i < m; day++){
            int cnt = 0;
            vector<int> cur;
            while(i < m && cnt < x && v[i].f <= day){
                if(day - d > v[i].f) valid = false;
                cur.PB(v[i].s);
                cnt++;
                i++;
            }
            tot += cur.size();
            cur_ans.PB(cur);
        }

        if(valid && tot == m) ans = cur_ans;
        return (valid && tot == m);
    });
    
    cout << mac << endl;
    for(int i = 0; i < n; i++){
        if(i < (int)ans.size()){
            for(int j : ans[i]){
                cout << j << ' ';
            }
        }
        cout << 0 << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2776 KB Output is correct
2 Correct 26 ms 2776 KB Output is correct
3 Correct 26 ms 2776 KB Output is correct
4 Correct 36 ms 2980 KB Output is correct
5 Correct 26 ms 2772 KB Output is correct
6 Correct 26 ms 2776 KB Output is correct
7 Correct 27 ms 3084 KB Output is correct
8 Correct 27 ms 3032 KB Output is correct
9 Correct 122 ms 3088 KB Output is correct
10 Correct 118 ms 3024 KB Output is correct
11 Correct 25 ms 3020 KB Output is correct
12 Correct 48 ms 5828 KB Output is correct
13 Correct 71 ms 9924 KB Output is correct
14 Correct 125 ms 12480 KB Output is correct
15 Correct 116 ms 13760 KB Output is correct
16 Correct 185 ms 19124 KB Output is correct
17 Correct 214 ms 21296 KB Output is correct
18 Correct 202 ms 22728 KB Output is correct
19 Correct 304 ms 26044 KB Output is correct
20 Correct 206 ms 20660 KB Output is correct