#include <bits/stdc++.h>
using namespace std;
int n,d,m;
pair<bool,vector<vector<int>>> check(const vector<pair<int,int>> &jobs,int count) {
vector<vector<int>> schedule(n);
int m=0;
for (int day=1; day<=n; day++) {
for (int j=0; j<count; j++) {
if (jobs[m].first>day) {
break;
}
if (jobs[m].first+d>=day) {
schedule[day-1].push_back(jobs[m++].second);
}
else {
return make_pair(false,schedule);
}
if (m==m) {
return make_pair(true,schedule);
}
}
}
return make_pair(false,schedule);
}
int main() {
cin >> n >> d >> m;
vector<pair<int,int>> jobs(m);
for (int i = 0; i < m; i++) {
int day;
cin >> day;
jobs[i] = make_pair(day,i+1);
}
sort(jobs.begin(),jobs.end());
vector<vector<int>> results;
int lower=1,upper=m;
while (lower<upper) {
int machines=(lower+upper)/2;
pair<bool,vector<vector<int>>> result =check(jobs,machines);
if (result.first) {
upper=machines;
results=result.second;
}
else
lower=machines+1;
}
cout << lower << endl;
for (int i=0; i<n; i++) {
for (int &idx:results[i]) cout << idx << " ";
cout << 0 << endl;
}
}
Compilation message
jobs.cpp: In function 'std::pair<bool, std::vector<std::vector<int> > > check(const std::vector<std::pair<int, int> >&, int)':
jobs.cpp:20:9: warning: self-comparison always evaluates to true [-Wtautological-compare]
20 | if (m==m) {
| ~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
1920 KB |
Output isn't correct |
2 |
Incorrect |
24 ms |
1924 KB |
Output isn't correct |
3 |
Incorrect |
23 ms |
1920 KB |
Output isn't correct |
4 |
Incorrect |
23 ms |
1920 KB |
Output isn't correct |
5 |
Incorrect |
23 ms |
1936 KB |
Output isn't correct |
6 |
Incorrect |
24 ms |
1924 KB |
Output isn't correct |
7 |
Incorrect |
23 ms |
1780 KB |
Output isn't correct |
8 |
Incorrect |
23 ms |
1784 KB |
Output isn't correct |
9 |
Incorrect |
126 ms |
8284 KB |
Output isn't correct |
10 |
Incorrect |
128 ms |
8440 KB |
Output isn't correct |
11 |
Incorrect |
20 ms |
1116 KB |
Output isn't correct |
12 |
Incorrect |
40 ms |
1880 KB |
Output isn't correct |
13 |
Incorrect |
61 ms |
2904 KB |
Output isn't correct |
14 |
Incorrect |
98 ms |
4216 KB |
Output isn't correct |
15 |
Incorrect |
102 ms |
4184 KB |
Output isn't correct |
16 |
Incorrect |
155 ms |
5672 KB |
Output isn't correct |
17 |
Incorrect |
198 ms |
6524 KB |
Output isn't correct |
18 |
Incorrect |
173 ms |
7292 KB |
Output isn't correct |
19 |
Incorrect |
320 ms |
14548 KB |
Output isn't correct |
20 |
Incorrect |
165 ms |
6520 KB |
Output isn't correct |