답안 #644751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644751 2022-09-25T07:33:38 Z Zflop Job Scheduling (CEOI12_jobs) C++14
100 / 100
421 ms 26460 KB
#include <bits/stdc++.h>
using namespace std;
 
/*
ID: 10002181
LANG: C++
TASK: ariprog
*/ 

using str = string; // yay python!
using ld = long double; // or double, if TL is tight
using ll = long long;
using int64 = ll;
using db = double;
using ull = unsigned long long;

#define ch() getchar()
#define pc(x) putchar(x)
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>; 
tcT, size_t SZ> using AR = array<T,SZ>; 
using vi = V<int>;
using vb = V<bool>;
using vpi = V<pair<int,int>>;
using vvi = V<vi>;
using vl = V<ll>;
using vd = V<ld>;
using vstr = V<str>;

#define mp make_pair
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x)) 
#define rev(x) reverse(all(x))
#define sz(x) (int)(x).size()
#define AR array
 
#define F0R(i, a, b) for (int i=a; i<b;++i)
#define FOR(i, a) for (int i=0; i<a;++i)
#define FORn(i, a) for (int i=1; i<=a;++i)
#define ROF(i,a) for(int i=a-1; i >= 0;--i)
#define R0F(i,a,b) for(int i=a; i > b;--i)
#define ROFn(i,a) for(int i=a; i > 0;--i)
#define trav(i,x) for(auto& i:x)
 
// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define lb lower_bound
#define ub upper_bound
#define SUM(v) accumulate(all(v), 0LL)
#define MN(v) *min_element(all(v))
#define MX(v) *max_element(all(v))
#define eb emplace_back
#define ft front()
#define bk back()
#define ins insert 
#define pf push_front
#define pb push_back
#define emt empty()
#define rsz resize

#define pob pop_back()
#define pof pop_front()

#define swp(a,b) a^=b^=a^=b

#define ts to_string
 
#define setIO()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const ll MOD = 1e9+7;
const ll MAX = 100000000000;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
 
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!

//INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(V<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(V<T>& x) { trav(a,x) re(a); }
tcT> void rv(int n, V<T>& x) { x.rsz(n); re(x); }

//OUTPUT
tcT> void pr(V<T>& x) { FOR(i,sz(x)) cout << x[i] << " \n"[i + 1 == sz(x)];}
tcT> void pr(T x) { cout << ts(x); }
tcT> void ps() { cout << '\n'; }


void setF(string fileName = "") {
	ios_base::sync_with_stdio(0); cin.tie(0);
	if((int)fileName.size()) {
		freopen((fileName+".in").c_str(), "r", stdin);
		freopen((fileName+".out").c_str(), "w", stdout);
	}
}

struct DSU {
	vector<int> e;
	DSU(int N) { e = vector<int>(N, -1); }
	
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }

	bool same_set(int a, int b) { return get(a) == get(b); }

	int size(int x) { return -e[get(x)]; }

	bool unite(int x, int y) {  // union by size
		x = get(x), y = get(y);
		if (x == y) return false;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y]; e[y] = x;
		return true;
	}
};
struct edge{
	int a;
	int b;
	int w;
	};

ll bpow(ll x, ll y){
    x %= MOD;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= MOD;
        x = (x*x) % MOD;
        y >>= 1LL;
    }
    return res;
}

ll gauss(int n){ return n*(n+1)/2; }

ll fact(int x){if(x) return x * (x - 1); return 1;}
/*
 scanf("%lld", &testInteger);
 printf("%lld", testInteger);
 
 ____ ____ ____ ____ ____  ____
||f |||l |||o |||p |||p ||||y ||
||__|||__|||__|||__|||__||||__||
|/__\|/__\|/__\|/__\|/__\||/__\|
 
**/
void solve(){
	int N,D,M; cin >> N >> D >> M;
	vpi A(M); FOR(i,M) { cin >> A[i].f; A[i].s = i + 1; }
	sor(A);
	vvi ans(N + 1);
	
	auto work = [&] (int x){
		vvi a(N);
		int k = 0;
		FORn(i,N){
			FOR(j,x){
				if(A[k].f > i) break;
				if(A[k].f + D >= i) a[i - 1].pb(A[k++].s);
				else return mp(false,a);
				if(k == M) return mp(true,a);
				}
			}
		return mp(false,a);
		};
	
	int l = 1,r = M;
	int aa = -1;
	while(l <= r){
		int mid = l + (r - l) / 2;
		auto a = work(mid);
		if(a.f) { 
			r = mid - 1; ans = a.s; 
			aa = mid;
			}
		else l = mid + 1;
		}
		
	cout << aa << '\n';
	FOR(i,sz(ans)){
		trav(x,ans[i]) cout << x << ' ';
		cout << "0\n";
		}
	}
// D - delay max 
// 8 2 12 
// 1 2 4 2 1 3 5 6 2 3 6 4
main()
{   setIO();
	solve();
} 
//is y a vowel? Damian:1
// <3 :L ._. <_< 
//You have no idea how high I can fly

Compilation message

jobs.cpp:210:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  210 | main()
      | ^~~~
jobs.cpp: In function 'void setF(std::string)':
jobs.cpp:114:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |   freopen((fileName+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:115:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |   freopen((fileName+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3040 KB Output is correct
2 Correct 31 ms 3044 KB Output is correct
3 Correct 30 ms 3000 KB Output is correct
4 Correct 31 ms 3000 KB Output is correct
5 Correct 29 ms 3040 KB Output is correct
6 Correct 29 ms 2988 KB Output is correct
7 Correct 29 ms 3032 KB Output is correct
8 Correct 31 ms 3012 KB Output is correct
9 Correct 74 ms 9524 KB Output is correct
10 Correct 65 ms 10496 KB Output is correct
11 Correct 36 ms 2776 KB Output is correct
12 Correct 78 ms 4944 KB Output is correct
13 Correct 105 ms 8592 KB Output is correct
14 Correct 177 ms 10804 KB Output is correct
15 Correct 191 ms 10956 KB Output is correct
16 Correct 246 ms 15840 KB Output is correct
17 Correct 318 ms 19056 KB Output is correct
18 Correct 330 ms 18292 KB Output is correct
19 Correct 421 ms 26460 KB Output is correct
20 Correct 309 ms 18832 KB Output is correct