Submission #152164

# Submission time Handle Problem Language Result Execution time Memory
152164 2019-09-06T16:04:47 Z 12tqian Job Scheduling (CEOI12_jobs) C++14
25 / 100
855 ms 55800 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
const double PI = 4 * atan(1);
 
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
 
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
 
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
 
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 1e5 + 5;
int ans = 0;
vi dates[MAX];
vpi jobs;
vi loc[MAX];
int n, d, m;
void gen(int use){
	
}
int check(int use){
	vpi left;
	for(auto x: jobs) left.eb(x);
	reverse(all(left));
	int avail = use;
	f1r(i, 1, n+1) dates[i].clear();
	int cur = 1;
	while(sz(left)>0){
		while(avail>0){
			if(sz(left) == 0){
				return 1;
			}
			avail--;
			int element = left[sz(left) - 1].f;
			dates[cur].eb(left[sz(left) - 1].s);
		//	cout << element + d << " " << cur << endl;
			if(element + d<cur) return 0;
			left.pop_back();
		}
		avail = use;
		cur++;
	}
	return 1;
	
}

int main(){
	fast_io();
	cin >> n >> d >> m;
	f0r(i, m){
		int t;
		cin >> t;
		jobs.eb(mp(t, i+1));
		loc[t].eb(i);
	}
	sort(all(jobs));
	int l = 1;
	int r = 1e6 + 5;
	while(abs(l-r)>1){
		int mid = (l + r)/2;
		if(check(mid)) r = mid;
		else l = mid+1;
	}
	if(l>r) swap(l, r);
	int val = -1;
	if(check(l)){
		//do nothing
		val = l;
	}
	else{
		val = r;
		check(r);
	}
//	gen(val);
	cout << val << endl;
	f1r(i, 1, n+1){
		for(auto x: dates[i]){
			cout << x << " ";
		}	
		cout << 0 << endl;
	}
	
	return 0;
}

Compilation message

jobs.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
jobs.cpp: In function 'void io(std::__cxx11::string)':
jobs.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
jobs.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 9968 KB Output isn't correct
2 Incorrect 79 ms 9976 KB Output isn't correct
3 Incorrect 80 ms 9940 KB Output isn't correct
4 Incorrect 81 ms 10272 KB Output isn't correct
5 Incorrect 79 ms 10244 KB Output isn't correct
6 Incorrect 81 ms 10180 KB Output isn't correct
7 Incorrect 83 ms 10264 KB Output isn't correct
8 Incorrect 79 ms 10344 KB Output isn't correct
9 Correct 329 ms 9944 KB Output is correct
10 Correct 339 ms 9996 KB Output is correct
11 Correct 65 ms 11192 KB Output is correct
12 Correct 127 ms 17108 KB Output is correct
13 Correct 197 ms 24804 KB Output is correct
14 Runtime error 284 ms 33064 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
15 Runtime error 298 ms 34920 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
16 Runtime error 462 ms 47316 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
17 Runtime error 524 ms 54912 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
18 Runtime error 541 ms 51416 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
19 Runtime error 855 ms 55800 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
20 Runtime error 492 ms 54728 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)