#include <bits/stdc++.h>
using namespace std;
//#include "soccer.h"
#define int long long
vector<int> monostack(vector<int> h){
vector<int> res = {0};
vector<int> x = {-1}, y;
int cur = 0;
for(int i = 0; i < h.size(); i++){
while(y.size() && h[i] >= y.back()){
cur -= y.back() * (x.back() - x[x.size()-2]);
y.pop_back();
x.pop_back();
}
cur += h[i] * (i - x.back());
y.push_back(h[i]);
x.push_back(i);
res.push_back(cur);
}
return res; // is this really the easiest way
//ill have to perfect it
}
int32_t biggest_stadium(int32_t N, std::vector<std::vector<int32_t>> F)
{
vector<vector<int>> u(N, {-1}), d(N, {N});
for(int i = N-1; i >= 0; i--){
for(int j = 0; j < N; j++){
if(F[i][j] == 1){
d[j].push_back(i);
}
}
}
int ans = N * N;
for(int i = 0; i < N; i++){
vector<int> t;
for(int j = 0; j < N; j++){
if(d[j].back() == i){
u[j].push_back(i);
}
}
vector<int> a;
for(int j = 0; j < N; j++) a.push_back(u[j].back()+1);
vector<int> b= monostack(a);
reverse(a.begin(), a.end());
vector<int> c= monostack(a);
vector<int> e;
for(int j = 0; j < N; j++) e.push_back(N - d[j].back());
vector<int> f = monostack(e);
reverse(e.begin(), e.end());
vector<int> g= monostack(e);
vector<int> l; int p = -1;
for(int j = 0; j < N; j++) {
if(F[i][j] == 1) p = j;
l.push_back(p);
}
p = N;
vector<int> r;
for(int j = N-1; j >= 0; j--){
if(F[i][j] == 1) p = j;
r.push_back(p);
}
reverse(r.begin(), r.end());
for(int j = 0; j < N; j++){
if(F[i][j] == 1) continue;
int tmp = b[j] + c[N-j-1] + f[j] + g[N-j-1]
- (l[j]+1) - (N-r[j]) + (u[j].back()+1) + (N-d[j].back());
ans = min(ans, tmp);
}
for(int j = 0; j < N; j++){
if(d[j].back() == i){
d[j].pop_back();
}
}
}
return N * N - ans;
}
Compilation message
soccer.cpp: In function 'std::vector<long long int> monostack(std::vector<long long int>)':
soccer.cpp:11:22: 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]
11 | for(int i = 0; i < h.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Partially correct |
1 ms |
348 KB |
partial |
7 |
Partially correct |
1 ms |
348 KB |
partial |
8 |
Partially correct |
23 ms |
2396 KB |
partial |
9 |
Partially correct |
413 ms |
32248 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Incorrect |
0 ms |
348 KB |
wrong |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Incorrect |
0 ms |
348 KB |
wrong |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Incorrect |
0 ms |
348 KB |
wrong |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Incorrect |
0 ms |
348 KB |
wrong |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
partial |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Partially correct |
1 ms |
348 KB |
partial |
8 |
Partially correct |
1 ms |
348 KB |
partial |
9 |
Partially correct |
23 ms |
2396 KB |
partial |
10 |
Partially correct |
413 ms |
32248 KB |
partial |
11 |
Incorrect |
0 ms |
348 KB |
wrong |
12 |
Halted |
0 ms |
0 KB |
- |