Submission #314435

# Submission time Handle Problem Language Result Execution time Memory
314435 2020-10-19T21:13:19 Z mohamedsobhi777 Strah (COCI18_strah) C++14
110 / 110
194 ms 4472 KB
#include <bits/stdc++.h>

/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/

#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5 + 7, mod = 1e9 + 7;
const int inf = N;
// How interesting!

int n, m;
int v[N];
ll ans;
int R[N];

void solve()
{
        stack<int> stk;
        for (int i = 0; i < m; ++i)
        {
                while (stk.size() && v[stk.top()] > v[i])
                {
                        R[stk.top()] = i - 1;
                        stk.pop();
                }
                stk.push(i);
        }
        while (stk.size())
        {
                R[stk.top()] = m - 1;
                stk.pop();
        }
        for (int i = 0; i < m; ++i)
        {
                int j1 = i, j2 = i;
                while (j1 && v[j1 - 1] > v[i])
                        --j1;
                j2 = R[i];
                ll contr = 0;
                ll l1 = i - j1, l2 = j2 - i;
                ll cof = 1ll * v[i] * (v[i] + 1) / 2ll;
                ll mult = (l1 + 1) * (l2 + 1) * (l2 + 2) / 2ll;
                mult += (l2 + 1) * (l1 + 1) * (l1) / 2ll;
                ans += cof * mult * 1ll ; 
        }
}

int main()
{

        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);
        cin >> n >> m;
        for (int i = 0; i < n; ++i)
        {
                for (int j = 0; j < m; ++j)
                {
                        char c;
                        cin >> c;
                        if (c == '.')
                                v[j]++;
                        else
                                v[j] = 0;
                }
                solve();
        }
        cout << ans;
        return 0;
}

Compilation message

strah.cpp: In function 'void solve()':
strah.cpp:53:20: warning: unused variable 'contr' [-Wunused-variable]
   53 |                 ll contr = 0;
      |                    ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 416 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 384 KB Output is correct
2 Correct 115 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 1532 KB Output is correct
2 Correct 171 ms 3992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 384 KB Output is correct
2 Correct 123 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 384 KB Output is correct
2 Correct 143 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 2808 KB Output is correct
2 Correct 193 ms 4472 KB Output is correct