#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 6031)
#define USACO freopen("haybales.in", "r", stdin); freopen("haybales.out", "w+", stdout);
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
pair<int, int> a[1000000];
vector<int> ans[100000];
bool check(int n, int cnt, int d, int m)
{
int l = 0;
for (int i = 1; i <= n; i++)
{
ans[i - 1].clear();
if (l < m && i - a[l].first > d)
{
return 0;
}
int cnt2 = 0;
while (cnt2 < cnt && l < m && a[l].first <= i)
{
ans[i - 1].push_back(a[l].second);
l++;
cnt2++;
}
}
return 1;
}
int main()
{
//USACO
fastIO;
int n, d, m;
cin >> n >> d >> m;
for (int i = 0; i < m; i++)
{
cin >> a[i].first;
a[i].second = i + 1;
}
sort(a, a + m);
int l = 1, r = m;
while (l < r)
{
int mid = l + (r - l) / 2;
if (check(n, mid, d, m))
{
r = mid;
}
else
{
l = mid + 1;
}
}
check(n, l, d, m);
cout << l << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < ans[i].size(); j++)
{
cout << ans[i][j] << " ";
}
cout << "0\n";
}
}
Compilation message
jobs.cpp:2: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
2 | #pragma warning(disable : 4996)
|
jobs.cpp:3: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
3 | #pragma warning(disable : 6031)
|
jobs.cpp: In function 'int main()':
jobs.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < ans[i].size(); j++)
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4784 KB |
Output is correct |
2 |
Correct |
21 ms |
4772 KB |
Output is correct |
3 |
Correct |
21 ms |
4860 KB |
Output is correct |
4 |
Correct |
22 ms |
4856 KB |
Output is correct |
5 |
Correct |
21 ms |
4820 KB |
Output is correct |
6 |
Correct |
23 ms |
4872 KB |
Output is correct |
7 |
Correct |
22 ms |
4888 KB |
Output is correct |
8 |
Correct |
25 ms |
4780 KB |
Output is correct |
9 |
Correct |
39 ms |
4944 KB |
Output is correct |
10 |
Correct |
33 ms |
4980 KB |
Output is correct |
11 |
Correct |
30 ms |
4868 KB |
Output is correct |
12 |
Correct |
57 ms |
7192 KB |
Output is correct |
13 |
Correct |
87 ms |
10172 KB |
Output is correct |
14 |
Correct |
133 ms |
13000 KB |
Output is correct |
15 |
Correct |
152 ms |
14748 KB |
Output is correct |
16 |
Correct |
174 ms |
18312 KB |
Output is correct |
17 |
Correct |
228 ms |
21836 KB |
Output is correct |
18 |
Correct |
244 ms |
21628 KB |
Output is correct |
19 |
Correct |
279 ms |
23512 KB |
Output is correct |
20 |
Correct |
214 ms |
21752 KB |
Output is correct |