# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
543109 | Saeed_247 | Job Scheduling (CEOI12_jobs) | C++14 | 222 ms | 16896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, d, arr[N];
vector<int> adj[N];
bool check(int x) {
queue<int> st;
int delay = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < arr[i]; j++) st.push(i);
int t = st.size();
for (int j = 0; j < min(x, t); j++) {
delay = max(delay, abs(i - st.front()));
st.pop();
}
}
if (!st.empty()) {
return false;
}
return delay <= d;
}
void print(int x) {
queue<int> st;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < arr[i]; j++) st.push(adj[i][j]);
int t = st.size();
for (int j = 0; j < min(x, t); j++) {
cout << st.front() << ' ';
st.pop();
}
cout << "0\n";
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> d >> m;
for (int i = 0; i < m; i++) {
int in; cin >> in;
arr[in]++;
adj[in].push_back(i + 1);
}
int lo = 1, hi = m;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
hi = mid;
}
else {
lo = mid + 1;
}
}
cout << hi << '\n';
print(hi);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |