제출 #747772

#제출 시각아이디문제언어결과실행 시간메모리
747772HyojinJob Scheduling (CEOI12_jobs)C++17
100 / 100
256 ms20308 KiB
#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1) 
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii> 
#define fi first
#define se second
#define ll long long
#define deb(x) cerr << #x << ' ' << x << '\n'
const int base=31;
const int MOD=1e9+7;
const int N=1e6+5;
void setIO(const string &NAME)
{
	if (NAME.size())
	{
		freopen((NAME+".inp").c_str(),"r",stdin);
		freopen((NAME+".out").c_str(),"w",stdout);
	}
}
int n,m,d;
pii a[N];
bool check(int x)
{
	int curJob=1;
	for (int days=1;days<=n;days++)
	{
		for (int machine=1;machine<=x;machine++)
		{
			if (a[curJob].fi>days) break;
			if (a[curJob].fi+d>=days) curJob++;
			else return false;
			if (curJob==m) return true;
		}
	}
	return false;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef izumiShiho
    	setIO("input");
	#endif //izumiShiho
    cin>>n>>d>>m;
    for (int i=1;i<=m;i++) 
    {
    	cin>>a[i].fi;
    	a[i].se=i;
    }
    sort(a+1,a+m+1);
	int l=1,r=m;
	while (l<=r)
	{
		int mid=l+r>>1;
		if (check(mid)) r=mid-1;
		else l=mid+1;
	}
	cout<<r+1<<"\n";
	vector<vector<int>>ans;
	ans.resize(n+1);
	int x=r+1;
	int curJob=1;
	for (int days=1;days<=n;days++)
	{
		for (int machine=1;machine<=x;machine++)
		{
			if (a[curJob].fi>days) break;
			if (a[curJob].fi+d>=days) 
			{
				ans[days].pb(a[curJob].se);
				curJob++;
			}
			if (curJob==m) break;
		}
		if (curJob==m) break;
	}
	for (int i=1;i<=n;i++)
	{
		for (auto x:ans[i]) cout<<x<<' ';
		cout<<0<<"\n";
	}
	return 0;
}

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

jobs.cpp: In function 'int main()':
jobs.cpp:57:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |   int mid=l+r>>1;
      |           ~^~
jobs.cpp: In function 'void setIO(const string&)':
jobs.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((NAME+".inp").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen((NAME+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...