제출 #652959

#제출 시각아이디문제언어결과실행 시간메모리
652959try_to_reach_next_rankJob Scheduling (CEOI12_jobs)C++14
80 / 100
349 ms42400 KiB
#include<bits/stdc++.h>
using namespace std;
#define forn(i,x,y,z) for(int i=x;i<y;i+=z)
#define form(i,x,y,z) for(int i=x;i>y;i+=z)
#define ll long long
#define gcd(a,b) (__gcd(a,b))
#define lcm(a,b) (a/gcd(a,b)*b)
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pb push_back
#define n_solve() ll test_case;cin>>test_case;forn(i,0,test_case,1){solve();}

const ll MAXN = 2e5+5;
const ll MOD = 1e9+7;
const ll MAXn = 1e5 + 5;

void solve(){
	ll n,d,m; cin>>n>>d>>m;
	pair<ll,ll> task[m];
	forn(i,0,m,1){
		cin>>task[i].first;
		task[i].second = i+1;
	}
	sort(task,task+m);
	
	vector<vector<ll>> ans;
	
	ll lo = 1, hi = m;
	while(lo<hi){
		ll mid = lo + (hi-lo)/2, request = 0,flag = 0,check = 0;
		vector<vector<ll>> schedule(n+1);
		forn(i,1,n+1,1){
			forn(j,0,mid,1){
				if(task[request].first > i ){
					break;
				}
				if(task[request].first + d >= i ){
					schedule[i-1].pb(task[request++].second);
				}else{
					check = 1;
					break;
				}
				if(request == m){
					flag = 1;
					check = 1;
					break;
				}
			}
			if(check)
				break;
		}
		if(flag){
			hi = mid;
			ans = schedule;
		}
		else{
			lo = mid + 1;
		}
	}
	cout<<lo<<endl;
	forn(i,0,n,1){
		for(auto &j:ans[i]){
			cout<<j<<" ";
		}
		cout<<"0\n";
	}
}

void fileio(string filename = ""){
	if((ll)(filename.size())){
		freopen((filename + ".in").c_str(), "r", stdin);
		freopen((filename + ".out").c_str(), "w", stdout);
	}
}

signed main(){	
	fileio();
    fast_cin();
	solve();
}

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'void fileio(std::string)':
jobs.cpp:70:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   freopen((filename + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:71:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   freopen((filename + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...