Submission #397068

# Submission time Handle Problem Language Result Execution time Memory
397068 2021-05-01T09:20:09 Z mewnian Bob (COCI14_bob) C++17
0 / 120
164 ms 42088 KB
#include <bits/stdc++.h>
#define sze(x) (ll)x.size()
#define idx(x, a) get<x>(a)
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;

const ll MAXN = 1e3 + 3;
const ll INF = 1e18 + 7;

ll a[MAXN][MAXN], h[MAXN][MAXN], l[MAXN][MAXN], cnt[MAXN][MAXN], m, n, res = 0;

int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    cin >> m >> n;
    for (ll i = 1; i <= m; ++i)
    {
        for (ll j = 1; j <= n; ++j) cin >> a[i][j];
        h[i][0] = h[i][n + 1] = -INF;
    }
    fill(h[1] + 1, h[1] + n + 1, 1);
    for (ll i = 2; i <= m; ++i)
        for (ll j = 1; j <= n; ++j)
            h[i][j] = (a[i][j] == a[i - 1][j] ? h[i - 1][j] + 1 : 1);
    for (ll i = 1; i <= m; ++i)
    {
        stack<ll> posL, posR;
        for (ll j = 1; j <= n; ++j)
        {
            if (j == 1 || a[i][j] != a[i][j - 1])
            {
                while (!posL.empty()) posL.pop();
                posL.push(j - 1);
            }
            else while (h[i][j] <= h[i][posL.top()]) posL.pop();
            l[i][j] = posL.top();
            posL.push(j);
            cnt[i][j] = (j - l[i][j]) * h[i][j] + cnt[i][l[i][j]] * (a[i][l[i][j]] == a[i][j]);
            //cout << cnt[i][j] << ' ';
            res += cnt[i][j];
        }
        //cout << endl;
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1356 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1364 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 16900 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 17348 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 17512 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 17516 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 123 ms 39588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 164 ms 42088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 157 ms 42024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 145 ms 41964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -