답안 #677194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677194 2023-01-02T14:24:49 Z sofija6 Job Scheduling (CEOI12_jobs) C++14
100 / 100
304 ms 27320 KB
#include <bits/stdc++.h>
#define ll int
#define MAXM 1000002
using namespace std;
ll n,d,m;
pair<ll,ll> a[MAXM];
bool Check(ll x)
{
    for (ll i=1;i<=x;i++)
    {
        ll cur=1;
        for (ll j=1;j<=m;j+=x)
        {
            if (cur<a[j].first)
                cur=a[j].first;
            if (cur-a[j].first>d)
                return false;
            cur++;
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> d >> m;
    for (ll i=1;i<=m;i++)
    {
        cin >> a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+1+m);
    ll l=1,r=m,mid,ans;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (Check(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    cout << ans << "\n";
    vector<pair<ll,ll> > v[ans+2];
    vector<ll> days[n+2];
    ll cur=1;
    for (ll i=1;i<=m;i++)
    {
        v[cur].push_back(a[i]);
        cur++;
        if (cur>ans)
            cur=1;
    }
    for (ll i=1;i<=ans;i++)
    {
        cur=1;
        for (ll j=0;j<v[i].size();j++)
        {
            if (cur<v[i][j].first)
                cur=v[i][j].first;
            days[cur].push_back(v[i][j].second);
            cur++;
        }
    }
    for (ll i=1;i<=n;i++)
    {
        for (ll j=0;j<days[i].size();j++)
            cout << days[i][j] << " ";
        cout << 0 << "\n";
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (ll j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
jobs.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for (ll j=0;j<days[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
jobs.cpp:33:20: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |     ll l=1,r=m,mid,ans;
      |                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5200 KB Output is correct
2 Correct 24 ms 5316 KB Output is correct
3 Correct 22 ms 5204 KB Output is correct
4 Correct 23 ms 5276 KB Output is correct
5 Correct 21 ms 5200 KB Output is correct
6 Correct 22 ms 5304 KB Output is correct
7 Correct 22 ms 5232 KB Output is correct
8 Correct 32 ms 5284 KB Output is correct
9 Correct 46 ms 6244 KB Output is correct
10 Correct 43 ms 6188 KB Output is correct
11 Correct 29 ms 3028 KB Output is correct
12 Correct 66 ms 5848 KB Output is correct
13 Correct 92 ms 9164 KB Output is correct
14 Correct 119 ms 13284 KB Output is correct
15 Correct 137 ms 13648 KB Output is correct
16 Correct 182 ms 18444 KB Output is correct
17 Correct 261 ms 23324 KB Output is correct
18 Correct 241 ms 22780 KB Output is correct
19 Correct 304 ms 27320 KB Output is correct
20 Correct 219 ms 23244 KB Output is correct