This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define NDEBUG
#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)
#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
constexpr ll INFTY = 2e18;
ll numrects(ll b, ll e, vector<ll>& table) {
ll s = e-b+1;
ll o =0;
for (ll i = b; i <= e; ++i)
{
for (ll j = i; j <= e; ++j)
{
ll m=INFTY;
for (ll k = i; k <= j; ++k)
{
m = min(m, table[k]);
}
o+=m;
}
}
return o;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll N,M;
cin >> N >> M;
vector<vector<ll>> H(N,vector<ll>(M,-1));
set<ll> posheights;
for (ll y = 0; y < N; ++y)
{
for (ll x = 0; x < M; ++x)
{
cin >> H[y][x];
}
}
ll outp=0;
vector<ll> uprun(M,1);
for (ll y = 0; y < N; ++y)
{
if (y!=0) {
for (ll x = 0; x < M; ++x)
{
if (H[y][x]==H[y-1][x]) {
uprun[x]++;
}
else {
uprun[x]=1;
}
}
}
ll runstart=0;
for (ll x = 1; x < M; ++x)
{
if (H[y][x]!=H[y][x-1]) {
outp+=numrects(runstart,x-1, uprun);
runstart=x;
}
}
outp+=numrects(runstart,M-1,uprun);
}
cout << outp;
}
Compilation message (stderr)
bob.cpp: In function 'll numrects(ll, ll, std::vector<long long int>&)':
bob.cpp:27:5: warning: unused variable 's' [-Wunused-variable]
27 | ll s = e-b+1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |