제출 #1277587

#제출 시각아이디문제언어결과실행 시간메모리
1277587vlqd0Job Scheduling (CEOI12_jobs)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

void setIO(string name = "") {
	if (name.length()) {
		(void)!freopen((name + ".in").c_str(), "r", stdin);
		(void)!freopen((name + ".out").c_str(), "w", stdout);
	}
}

int n, d, m;
vector<vector<int>> days;
bool check(int original){
    queue<pair<int, int>> q;
    int remaining, machines;
    for (int i = 1; i <= n; i++){
        machines = original;
        while(!q.empty() and machines > 0){
            if (i - d > q.front().first) return false;
            
            if (q.front().second <= machines){
                machines -= q.front().second;
                q.pop();
            } else {
                q.front().second -= machines;
                machines = 0;
            }
        }

        remaining = days[i].size();
        if (machines > 0) remaining = max(0, remaining - machines);
        if (remaining > 0) q.push({i, remaining});
    }
    
    if (!q.empty()) return false;
    return true;
}
 
void solve(){
    cin >> n >> d >> m;
    days.resize(n + 1);
    int c;
    for (int i = 1; i <= m; i++){
        cin >> c;
        days[c].push_back(i);
    }

    int l = 1, r = 1e6, mid, ans = INT_MAX;
    while(l <= r){
        mid = (l + r) / 2;
        if (check(mid)){
            ans = min(ans, mid);
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    
    cout << ans << "\n";
    queue<int> q;
    int m;
    for (int i = 1; i <= n; i++){
        if (i <= n - d){
            m = ans;
            while(!q.empty() and m > 0){
                cout << q.front() << " ";
                m--;
                q.pop();
            }
            
            for (int j : days[i]){
                if (m > 0) {cout << j << " "; m--;}
                else q.push(j);
            }
        }
        cout << 0 << "\n";
    }
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //setIO("swap");
    
    solve();
    
    return 0;
}

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

jobs.cpp: In function 'bool check(long long int)':
jobs.cpp:32:42: error: no matching function for call to 'max(int, long long int)'
   32 |         if (machines > 0) remaining = max(0, remaining - machines);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from jobs.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
jobs.cpp:32:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |         if (machines > 0) remaining = max(0, remaining - machines);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
jobs.cpp:32:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   32 |         if (machines > 0) remaining = max(0, remaining - machines);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
jobs.cpp:32:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |         if (machines > 0) remaining = max(0, remaining - machines);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
jobs.cpp:32:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 |         if (machines > 0) remaining = max(0, remaining - machines);
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~