답안 #862135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862135 2023-10-17T14:32:19 Z vjudge1 Job Scheduling (CEOI12_jobs) C++14
0 / 100
160 ms 33708 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,d,m;
vector<int> a,index_v;
bool is_ok(int machine)
{
	int ptr=0;
	for(int day=1;day<=n;++day)
	{
		for(int i=0;i<machine;++i)
		{
			if(ptr>=a.size()) return true;
			if(a[ptr]>day) break;
			if(a[ptr]+d<day) return false;
			++ptr;
		}
	}
	return (ptr>=a.size());
}
void yes(int machine)
{
	int ptr=0;
	for(int day=1;day<=n;++day)
	{
		for(int i=0;i<machine;++i)
		{
			if(ptr>=index_v.size()||a[ptr]>day) break;
			cout<<index_v[ptr++]<<' ';
		}
		cout<<0<<'\n';
	}
}
main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>d>>m;
	vector<pair<int,int>> tmp(m);
	for(int i=0;i<m;++i) cin>>tmp[i].first,tmp[i].second=i+1;
	sort(tmp.begin(),tmp.end());
	for(auto it:tmp) a.push_back(it.first),index_v.push_back(it.second);
	int l=0,r=1e9,ans=1e9;
	while(l<=r)
	{
		int mid=(r-l)/2+l;
		if(is_ok(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<'\n';
//	yes(ans);
	return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

Compilation message

jobs.cpp: In function 'bool is_ok(long long int)':
jobs.cpp:13:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |    if(ptr>=a.size()) return true;
      |       ~~~^~~~~~~~~~
jobs.cpp:19:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  return (ptr>=a.size());
      |          ~~~^~~~~~~~~~
jobs.cpp: In function 'void yes(long long int)':
jobs.cpp:28:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    if(ptr>=index_v.size()||a[ptr]>day) break;
      |       ~~~^~~~~~~~~~~~~~~~
jobs.cpp: At global scope:
jobs.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 4048 KB Unexpected end of file - int32 expected
2 Incorrect 11 ms 3980 KB Unexpected end of file - int32 expected
3 Incorrect 11 ms 4048 KB Unexpected end of file - int32 expected
4 Incorrect 12 ms 4048 KB Unexpected end of file - int32 expected
5 Incorrect 11 ms 4048 KB Unexpected end of file - int32 expected
6 Incorrect 11 ms 4048 KB Unexpected end of file - int32 expected
7 Incorrect 11 ms 3984 KB Unexpected end of file - int32 expected
8 Incorrect 11 ms 3980 KB Unexpected end of file - int32 expected
9 Incorrect 16 ms 4044 KB Unexpected end of file - int32 expected
10 Incorrect 17 ms 4044 KB Unexpected end of file - int32 expected
11 Incorrect 17 ms 4048 KB Unexpected end of file - int32 expected
12 Incorrect 35 ms 7648 KB Unexpected end of file - int32 expected
13 Incorrect 53 ms 14508 KB Unexpected end of file - int32 expected
14 Incorrect 76 ms 15396 KB Unexpected end of file - int32 expected
15 Incorrect 86 ms 17840 KB Unexpected end of file - int32 expected
16 Incorrect 111 ms 27840 KB Unexpected end of file - int32 expected
17 Incorrect 129 ms 28844 KB Unexpected end of file - int32 expected
18 Incorrect 140 ms 30960 KB Unexpected end of file - int32 expected
19 Runtime error 160 ms 33708 KB Memory limit exceeded
20 Incorrect 129 ms 27876 KB Unexpected end of file - int32 expected