답안 #784426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784426 2023-07-16T06:16:31 Z whatthemomooofun1729 Job Scheduling (CEOI12_jobs) C++14
100 / 100
359 ms 17536 KB
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#include <numeric>
//#include <bit>

#define INF 2e9
#define LL_INF 9223372036854775806
#define ff first
#define ss second
#define mod 1000000007
#define ll long long
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define EB emplace_back
#define PoB pop_back
#define LOG log2
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define fch(t, v) for (auto t : v)
#define sz(x) int(x.size())
#define rsz resize
#define gp(x) vector<vector<x>>
#define btree vector<pii>
#define vc(x) vector<x>
#define vll vector<ll>
#define Max(a, b, c) max(max(a,b),c)
#define fMax(a, b, c, d) max(Max(a, b, c), d)
#define Min(a, b, c) min(min(a,b),c)
#define Mid(a, b, c) max(min(a, b), min(max(a, b), c))
#define st(a) set<a>
#define gr(x) greater<x>
#define gi greater<int>
#define all(x) (x).begin(),(x).end()
#define tri(x) tuple<x,x,x>
#define quad(x) tuple<x,x,x,x>
#define eps 1e-9

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

void setIO(const string& str) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (str.empty()) return;
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}

int N, D, M;
vi req;
vc(pii) idx;

int main() {
    setIO("");
    cin >> N >> D >> M;
    req.rsz(M);
    for (int i = 0; i < M; ++i) {
        cin >> req[i];
        idx.PB({req[i], i});
    }
    sort(all(req)), sort(all(idx));
    int l = 1, r = M;
    auto check = [&](int x) ->bool {
        int day = 1, cnt = 0;
        for (int i = 0; i < M; ++i) {
            cnt++;
            if (req[i] > day) day = req[i], cnt = 0;
            if (day-req[i] > D) return false;
            if (cnt == x) cnt = 0, day++;
        }
        return true;
    };
    while (l <= r) {
        int mid = (l + r)/2;
        if (check(mid)) {
            r = mid-1;
        } else {
            l = mid+1;
        }
    }
    cout << r+1 << endl;
    int i = 0;
    int d = 0;
    while (i < M) {
        for (int j = 1; j <= r+1; ++j) {
            cout << idx[i++].ss+1 << " ";
            if (i == M) break;
        }
        cout << 0 << endl;
        d++;
    }
    for (int j = d+1; j <= N; ++j) {
        cout << 0 << endl;
    }
}

Compilation message

jobs.cpp: In function 'void setIO(const string&)':
jobs.cpp:92:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |     freopen((str + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:93:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |     freopen((str + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2352 KB Output is correct
2 Correct 41 ms 2360 KB Output is correct
3 Correct 27 ms 2320 KB Output is correct
4 Correct 27 ms 2352 KB Output is correct
5 Correct 27 ms 2264 KB Output is correct
6 Correct 42 ms 2324 KB Output is correct
7 Correct 41 ms 2364 KB Output is correct
8 Correct 29 ms 2352 KB Output is correct
9 Correct 121 ms 2532 KB Output is correct
10 Correct 132 ms 2580 KB Output is correct
11 Correct 40 ms 2284 KB Output is correct
12 Correct 58 ms 4208 KB Output is correct
13 Correct 85 ms 6080 KB Output is correct
14 Correct 130 ms 7972 KB Output is correct
15 Correct 141 ms 9832 KB Output is correct
16 Correct 197 ms 11756 KB Output is correct
17 Correct 252 ms 13536 KB Output is correct
18 Correct 234 ms 15412 KB Output is correct
19 Correct 359 ms 17536 KB Output is correct
20 Correct 259 ms 13612 KB Output is correct