답안 #1085568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085568 2024-09-08T12:31:07 Z vjudge1 Job Scheduling (CEOI12_jobs) C++17
100 / 100
279 ms 17080 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
vector<int>v[100001];
bool check(int x)
{
    int t=v[1].size(),l=1;
    for(int i=1;i<=k;i++)
    {
        int temp=x;
        if(l+m<i)
        {
            return false;
        }
        while(l<=i)
        {
            if(t<=temp)
            {
                l++;
                temp-=t;
                t=v[l].size();
            }
            else
            {
                t-=temp;
                break;
            }
        }
    }
    if(l!=k+1)
    {
        return false;
    }
    return true;
}
int main()
{
    int a;
    cin>>k>>m>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v[a].push_back(i+1);
    }
    int l=1,r=n;
    while(l<r)
    {
        int mid=(l+r)/2;
        if(check(mid))
        {
            r=mid;
        }
        else
        {
            l=mid+1;
        }
    }
    cout<<r<<endl;
    l=1;
    int t=v[1].size(),lx=0;
    for(int i=1;i<=k;i++)
    {
          int temp=r;
          while(l<=i)
          {
            if(t<=temp)
            {
                for(int j=lx;j<v[l].size();j++)
                {
                    cout<<v[l][j]<<" ";
                }
                l++;
                lx=0;
                temp-=t;
                t=v[l].size();
            }
            else
            {
                for(int j=lx;j<lx+temp;j++)
                {
                    cout<<v[l][j]<<" ";
                }
                lx+=temp;
                t-=temp;
                break;
            }
          }
          cout<<"0"<<endl;
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:68:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 for(int j=lx;j<v[l].size();j++)
      |                              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 4048 KB Output is correct
2 Correct 28 ms 4052 KB Output is correct
3 Correct 27 ms 4144 KB Output is correct
4 Correct 28 ms 4052 KB Output is correct
5 Correct 32 ms 4204 KB Output is correct
6 Correct 29 ms 3964 KB Output is correct
7 Correct 29 ms 4048 KB Output is correct
8 Correct 27 ms 4052 KB Output is correct
9 Correct 114 ms 4432 KB Output is correct
10 Correct 115 ms 4436 KB Output is correct
11 Correct 21 ms 4184 KB Output is correct
12 Correct 40 ms 5712 KB Output is correct
13 Correct 60 ms 8016 KB Output is correct
14 Correct 102 ms 9808 KB Output is correct
15 Correct 103 ms 11088 KB Output is correct
16 Correct 141 ms 13628 KB Output is correct
17 Correct 163 ms 15952 KB Output is correct
18 Correct 155 ms 15772 KB Output is correct
19 Correct 279 ms 17080 KB Output is correct
20 Correct 175 ms 15928 KB Output is correct