답안 #1051872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051872 2024-08-10T10:20:28 Z manhlinh1501 Job Scheduling (CEOI12_jobs) C++17
10 / 100
76 ms 38228 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 1e6 + 5;

int N, M, D;
int a[MAXN];
vector<int> g[MAXN];

bool check(int K) {
    int cnt = 0;
    for(int i = 1; i <= N; i++) {
        cnt += g[i].size();
        if(cnt > K * D) return false;
        cnt = cnt - min(cnt, K);
    }
    return true;
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> D >> M;
    for(int i = 1; i <= M; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= M; i++) g[a[i]].emplace_back(i);
    int low = 1, high = M;
    int ans = -1;
    while(low <= high) {
        int mid = (low + high) / 2;
        if(check(mid)) {
            ans = mid;
            high = mid - 1;
        } else low = mid + 1;
    }
    cout << ans << "\n";
    queue<int> Q;
    for(int i = 1; i <= N; i++) {
        for(int p : g[i])
            Q.emplace(p);
        int cnt = 0;
        while(!Q.empty() and cnt < ans) {
            int p = Q.front();
            cout << p << " ";
            Q.pop();
            cnt++;
        }
        cout << "0\n";
    }
    return (0 ^ 0);
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 26584 KB Output isn't correct
2 Incorrect 11 ms 26588 KB Output isn't correct
3 Incorrect 11 ms 26596 KB Output isn't correct
4 Incorrect 11 ms 26672 KB Output isn't correct
5 Incorrect 11 ms 26588 KB Output isn't correct
6 Incorrect 10 ms 26700 KB Output isn't correct
7 Incorrect 11 ms 26584 KB Output isn't correct
8 Incorrect 11 ms 26588 KB Output isn't correct
9 Incorrect 13 ms 26716 KB Output isn't correct
10 Incorrect 17 ms 26456 KB Output isn't correct
11 Correct 12 ms 26200 KB Output is correct
12 Incorrect 19 ms 27480 KB Output isn't correct
13 Correct 29 ms 29468 KB Output is correct
14 Incorrect 40 ms 32596 KB Output isn't correct
15 Runtime error 43 ms 33620 KB Memory limit exceeded
16 Runtime error 57 ms 35152 KB Memory limit exceeded
17 Runtime error 68 ms 37204 KB Memory limit exceeded
18 Runtime error 68 ms 37292 KB Memory limit exceeded
19 Runtime error 76 ms 38228 KB Memory limit exceeded
20 Runtime error 66 ms 37208 KB Memory limit exceeded