답안 #304879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304879 2020-09-22T05:37:07 Z waterfall Job Scheduling (CEOI12_jobs) C++11
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

string s = "";

bool works(int num, int m, pair<int, int> requests[m], int delay)
{
    int arr[num+1];
    memset(arr, 0, sizeof(arr));

    for(int i = 0; i < m; i++)
    {
        int machineNum = i % num;
        int day = max(requests[i].first, arr[machineNum] + 1);
        if(abs(requests[i].first - day) > delay)
        {
            return false;
        }

        arr[machineNum]++;
    }

    return true;

}

int32_t main()
{
    int n, d, m;
    cin >> n >> d >> m;

    pair<int, int> requests[m];
    for(int i = 0; i < m; i++)
    {
        int temp;
        cin >> temp;
        requests[i] = make_pair(temp, (i+1));
    }

    sort(requests, requests + m);

    int lower = 1;
    int upper = m;
    while(lower != upper)
    {
        int mid = (lower + upper ) / 2;
        if(works(mid, m, requests, d))
        {
            upper = mid;
        }
        else
        {
            lower = mid + 1;
        }
    }

    cout << lower << endl;

    int arr[lower + 1];
    memset(arr, 0, sizeof(arr));

    int curDay = 1;
    for(int i = 0; i < m; i++)
    {
        int machineNum = i % lower;
        int day = max(requests[i].first, arr[machineNum] + 1);
        arr[machineNum]++;

        if(day == curDay)
        {
            cout << requests[i].second << " ";
        }
        else if(day == curDay + 1)
        {
            cout << "0" << endl;
            cout << requests[i].second << " ";
            curDay = day;
        }
        else
        {
            for(int i = day; i < curDay - 1; i++)
            {
                cout << "0" << endl;
            }
            cout << requests[i].second << " ";
            curDay = day;
        }
    }

    cout << "0" << endl;
    if(curDay != n)
    {
        for(int i = curDay; i < n; i++)
        {
            cout << "0" << endl;
        }
    }
    return 0;
}


Compilation message

jobs.cpp:24:53: error: use of parameter outside function body before ']' token
   24 | bool works(int num, int m, pair<int, int> requests[m], int delay)
      |                                                     ^
jobs.cpp:24:54: error: expected ')' before ',' token
   24 | bool works(int num, int m, pair<int, int> requests[m], int delay)
      |           ~                                          ^
      |                                                      )
jobs.cpp:6:25: error: expected unqualified-id before 'long'
    6 | #define int             long long
      |                         ^~~~
jobs.cpp:24:56: note: in expansion of macro 'int'
   24 | bool works(int num, int m, pair<int, int> requests[m], int delay)
      |                                                        ^~~