#include<bits/stdc++.h>
using namespace std;
#define int long long
const int TAILLE_MAX=1000+5,INFINI=1000*1000*1000;
int nbVal,posInit,tempsInit;
int val[TAILLE_MAX];
int dv[TAILLE_MAX][TAILLE_MAX],pb[TAILLE_MAX][TAILLE_MAX];
vector<int> calcCumu(vector<int> v) {
vector<int> ans={0};
int somCour=0;
for (int i:v) {
somCour+=i;
ans.push_back(somCour);
}
return ans;
}
void DFS(int lig,int col) {
if (pb[lig][col]==0 and dv[lig][col]==0) {
dv[lig][col]=1;
DFS(lig+1,col);
DFS(lig,col+1);
}
}
bool verif(int temps) {
//cout<<temps<<endl;
vector<int> listeGau,listeDro;
for (int i=posInit;i>1;i--) {
listeGau.push_back(2*temps-val[i]+val[i-1]);
}
for (int i=posInit+1;i<=nbVal;i++) {
listeDro.push_back(2*temps-val[i]+val[i-1]);
}
vector<int> cumuGau=calcCumu(listeGau),cumuDro=calcCumu(listeDro);
int tailleGau=cumuGau.size(),tailleDro=cumuDro.size();
for (int i=0;i<=tailleGau;i++) {
for (int j=0;j<=tailleDro;j++) {
pb[i][j]=1;
dv[i][j]=0;
}
}
for (int i=0;i<tailleGau;i++) {
for (int j=0;j<tailleDro;j++) {
if (cumuGau[i]+cumuDro[j]>=0) {
pb[i][j]=0;
}
}
}
/*for (int i:cumuGau) {
for (int j:cumuDro) {
if (i+j>=0) {
cout<<1<<" ";
}
else {
cout<<0<<" ";
}
}
cout<<endl;
}
cout<<endl;*/
DFS(0,0);
return (dv[tailleGau-1][tailleDro-1]==1);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbVal>>posInit>>tempsInit;
for (int i=1;i<=nbVal;i++) {
cin>>val[i];
}
int deb=0,fin=INFINI,mid;
while (deb!=fin) {
mid=(deb+fin)/2;
if (verif(mid)) {
fin=mid;
}
else {
deb=mid+1;
}
}
cout<<(deb+tempsInit-1)/tempsInit<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2488 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2512 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2488 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2512 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
12 ms |
6744 KB |
Output is correct |
23 |
Correct |
8 ms |
6748 KB |
Output is correct |
24 |
Correct |
4 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
13 ms |
6748 KB |
Output is correct |
27 |
Correct |
15 ms |
6748 KB |
Output is correct |
28 |
Correct |
24 ms |
14940 KB |
Output is correct |
29 |
Correct |
23 ms |
14940 KB |
Output is correct |
30 |
Correct |
17 ms |
14936 KB |
Output is correct |
31 |
Correct |
20 ms |
14940 KB |
Output is correct |
32 |
Correct |
25 ms |
10980 KB |
Output is correct |
33 |
Correct |
26 ms |
11096 KB |
Output is correct |
34 |
Correct |
14 ms |
14940 KB |
Output is correct |
35 |
Correct |
24 ms |
14940 KB |
Output is correct |
36 |
Correct |
9 ms |
6744 KB |
Output is correct |
37 |
Correct |
8 ms |
6748 KB |
Output is correct |
38 |
Correct |
25 ms |
15032 KB |
Output is correct |
39 |
Correct |
8 ms |
15452 KB |
Output is correct |
40 |
Correct |
30 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2488 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2512 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
12 ms |
6744 KB |
Output is correct |
23 |
Correct |
8 ms |
6748 KB |
Output is correct |
24 |
Correct |
4 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
13 ms |
6748 KB |
Output is correct |
27 |
Correct |
15 ms |
6748 KB |
Output is correct |
28 |
Correct |
24 ms |
14940 KB |
Output is correct |
29 |
Correct |
23 ms |
14940 KB |
Output is correct |
30 |
Correct |
17 ms |
14936 KB |
Output is correct |
31 |
Correct |
20 ms |
14940 KB |
Output is correct |
32 |
Correct |
25 ms |
10980 KB |
Output is correct |
33 |
Correct |
26 ms |
11096 KB |
Output is correct |
34 |
Correct |
14 ms |
14940 KB |
Output is correct |
35 |
Correct |
24 ms |
14940 KB |
Output is correct |
36 |
Correct |
9 ms |
6744 KB |
Output is correct |
37 |
Correct |
8 ms |
6748 KB |
Output is correct |
38 |
Correct |
25 ms |
15032 KB |
Output is correct |
39 |
Correct |
8 ms |
15452 KB |
Output is correct |
40 |
Correct |
30 ms |
10844 KB |
Output is correct |
41 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |