제출 #1334908

#제출 시각아이디문제언어결과실행 시간메모리
1334908dhuyyyyJob Scheduling (CEOI12_jobs)C++20
100 / 100
448 ms15796 KiB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define MASK(i) (1LL << i)

using namespace std;

using ii = pair<int,int>;
using aa = array<int,3>;

const int N = 2e5+5;
const int Q = 5e5+5;
const int INF = 1e18;
const int MOD = 1e9;
 
int n, x, d, m, ans;

vector <int> adj[N];

bool ok(int mid){
    priority_queue<int,vector<int>,greater<int>> pq;
    for (int i = 1; i <= n; i++){
        for (int it : adj[i]) pq.push(i);
        int k = sz(pq);
        for (int j = 0; j < min(k,mid); j++){
            if (pq.top() + d < i) return 0;
            pq.pop();
        }
    }
    return 1;
}

void solve(int mid){
    priority_queue<ii,vector<ii>,greater<ii>> pq;
    for (int i = 1; i <= n; i++){
        for (int it : adj[i]){
            pq.push({i,it});
        }
        int k = sz(pq);
        for (int j = 0; j < min(k,mid); j++){
            cout << pq.top().se << ' ';
            pq.pop();
        }
        cout << 0 << '\n';
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #define name "main"
    if (fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    cin >> n >> d >> m;
    for (int i = 1; i <= m; i++){
        cin >> x;
        adj[x].push_back(i);
    }
    int l = 1, r = m;
    while (l <= r){
        int mid = (l + r) >> 1;
        if (ok(mid)){
            ans = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    cout << ans << '\n';
    solve(ans);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'int main()':
jobs.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...