Submission #696982

# Submission time Handle Problem Language Result Execution time Memory
696982 2023-02-07T19:35:17 Z koolaider Job Scheduling (CEOI12_jobs) C++17
90 / 100
340 ms 13812 KB
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
 
void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}
 
 
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define pb push_back
#define ll long long
#define cint const int

 
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");}
//binar, dp, starcod, coci,   / bfs,    /seg    /longest path
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


#pragma GCC target ("avx,avx2")
#pragma GCC optimize ("O3")
 
const long long ML = 1e18;
cint MN = 1e9;
cint MA = 2e5+1;
cint MM = 1e9+7;

int main(int argc, char **argv){
	ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);
	int n, d, m; cin >> n >> d >> m; vector<pair<int, int>> v; int x;
	for(int i = 0; i<m; i++){ 
		cin >> x; //x--;
		 v.pb({x, i+1});
	}
	sort(v.begin(), v.end()); //debug(v);
	int l=1, r=m; int ans = MN;
	while(l<=r){
		int mid=(l+r)/2;
		//int curr=m-(n*mid);
		
		int currDay=1; int Clock=0; bool isOk=true;
			for(int i = 0; i<m; i++){
			bool lol=false;
			if(currDay<v[i].first){
				lol=true;
				}
			if(currDay-v[i].first>d){//instead of d use time in queue
				isOk=false; break;
				}
			Clock++;
			if(Clock==mid){
				currDay++; Clock=0;
				}
				if(lol==true) currDay++;
			}
			if(isOk==true){
				ans=min(ans, mid);
				}
				
		if(isOk==false){//curr>0
		l=mid+1;
		}else if(isOk==true){//curr<=0
			r=mid-1; 
			}
		}
		cout << ans << endl; int outputCounter=0;
		for(int i = 0; i<m; i++){
			cout << v[i].second << " ";
			outputCounter++;
			if(outputCounter==ans){
				cout << 0 << endl; outputCounter=0;
			}
			}
		for(int i = 0; i<n-(m/ans); i++){
			cout << 0 << endl;
			}
	return 0;
}

/*

8 2 12
1 2 4 2 1 3 5 6 2 3 6 4 

8 1 12
1 2 4 2 1 3 5 6 2 3 6 4 

8 0 12
1 2 4 2 1 3 5 6 2 3 6 4 

8 8 12
1 2 4 2 1 3 5 6 2 3 6 4 



*/

Compilation message

jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:6:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen((s + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1744 KB Output is correct
2 Correct 28 ms 1760 KB Output is correct
3 Correct 30 ms 1844 KB Output is correct
4 Correct 33 ms 1840 KB Output is correct
5 Correct 29 ms 1820 KB Output is correct
6 Correct 29 ms 1840 KB Output is correct
7 Correct 29 ms 1856 KB Output is correct
8 Correct 29 ms 1844 KB Output is correct
9 Correct 142 ms 2016 KB Output is correct
10 Correct 139 ms 1964 KB Output is correct
11 Correct 25 ms 1736 KB Output is correct
12 Correct 51 ms 3260 KB Output is correct
13 Correct 80 ms 4716 KB Output is correct
14 Correct 134 ms 6200 KB Output is correct
15 Incorrect 133 ms 7704 KB Output isn't correct
16 Correct 182 ms 9180 KB Output is correct
17 Correct 201 ms 10672 KB Output is correct
18 Correct 233 ms 12216 KB Output is correct
19 Incorrect 340 ms 13812 KB Output isn't correct
20 Correct 197 ms 10736 KB Output is correct