#include <bits/stdc++.h>
#define DIMN 1000010
using namespace std;
int dp[DIMN];
int mp[DIMN];
int tt[DIMN];
int w[DIMN] , poz[DIMN];
pair <int , int> v[DIMN];
FILE *fin = stdin;
FILE *fout = stdout;
int ok (int maxi , int n , int ok){
int now , a , b , st , dr , mid;
now = n;
while (now){ /// nu pare o idee buna ce fac....
a = max(0 , now - maxi); /// ma asigur ca v2 nu e -1
/// cea mai mica echipa posibila ar fi de v[now].first
b = now - v[now].first;
while (tt[b] == -1)
b--;
/// a <= b
if (a > b)
swap(a , b);
a = poz[a];
b = poz[b];
st = a;
dr = b;
while (st <= dr){
mid = (st + dr)/2;
if (dp[w[mid]] + 1 == dp[now])
dr = mid - 1;
else st = mid + 1;
}
if (ok)
fprintf (fout,"%d " , now - w[st]);
if (now - w[st] > maxi)
return 0;
while (now > w[st]){
if (ok)
fprintf (fout,"%d ",v[now].second);
now--;
}
if (ok)
fprintf (fout,"\n");
}
return 1;
}
int main()
{
int n , i , st , dr , mid , elem;
fscanf (fin,"%d",&n);
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%d",&v[i].first);
v[i].second = i;
}
sort (v + 1 , v + n + 1);
elem = 0;
for (i = 1 ; i <= n ; i++){
if (i - v[i].first < 0){
dp[i] = -2000000000;
mp[i] = mp[i - 1];
tt[i] = -1;
}
else {
dp[i] = mp[i - v[i].first] + 1;
w[++elem] = i;
poz[i] = elem;
tt[i] = i - v[i].first;
mp[i] = max(mp[i - 1] , dp[i]);
}
}
fprintf (fout,"%d\n" , dp[n]);
st = v[n].first;
dr = n;
while (st <= dr){
mid = (st + dr)/2;
if (ok(mid , n , 0))
dr = mid - 1; /// merge, cauti mai mic
else st = mid + 1;
}
/// solutia e st (dim minima a echipei maxime)
//printf ("%d ",st);
ok(st , n , 1);
return 0;
}
Compilation message
tea.cpp: In function 'int main()':
tea.cpp:73:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
73 | fscanf (fin,"%d",&n);
| ~~~~~~~^~~~~~~~~~~~~
tea.cpp:75:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
75 | fscanf (fin,"%d",&v[i].first);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3268 KB |
Output is correct |
2 |
Correct |
28 ms |
3216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3748 KB |
Output is correct |
2 |
Correct |
30 ms |
3016 KB |
Output is correct |
3 |
Correct |
32 ms |
3664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
29576 KB |
Output is correct |
2 |
Correct |
295 ms |
28188 KB |
Output is correct |
3 |
Correct |
277 ms |
30132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
363 ms |
39856 KB |
Output is correct |
2 |
Correct |
963 ms |
39560 KB |
Output is correct |
3 |
Correct |
399 ms |
37516 KB |
Output is correct |
4 |
Correct |
345 ms |
35292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
38144 KB |
Output is correct |
2 |
Correct |
279 ms |
34572 KB |
Output is correct |
3 |
Correct |
362 ms |
38480 KB |
Output is correct |
4 |
Correct |
388 ms |
40292 KB |
Output is correct |