Submission #305099

# Submission time Handle Problem Language Result Execution time Memory
305099 2020-09-22T15:08:33 Z phathnv Strah (COCI18_strah) C++11
110 / 110
123 ms 70904 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "Strah"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 2001;

int m, n;
char s[N][N];

int h[N];
ll sumS[N][N], sumH[N][N];

void readInput(){
    scanf("%d %d", &m, &n);
    for(int i = 1; i <= m; i++)
        scanf("%s", s[i] + 1);
}

void solve(){
    ll res = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++)
            if (s[i][j] == '.')
                h[j]++;
            else
                h[j] = 0;

        stack <int> st;
        st.push(0);
        h[0] = -1;

        for(int j = 1; j <= n; j++){
            while (h[st.top()] >= h[j])
                st.pop();

            int w = j - st.top();
            sumS[i][j] = sumS[i][st.top()] + sumH[i][st.top()] * w;
            sumS[i][j] += (ll) h[j] * (h[j] + 1) * w * (w + 1) / 4;
            sumH[i][j] = sumH[i][st.top()] + h[j] * (h[j] + 1) / 2 * w;
            st.push(j);

            res += sumS[i][j];
        }
    }
    cout << res;
}

int main(){
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    readInput();
    solve();
    return 0;
}

Compilation message

strah.cpp: In function 'void readInput()':
strah.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |     scanf("%d %d", &m, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
strah.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%s", s[i] + 1);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4864 KB Output is correct
2 Correct 5 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 5 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 5 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 26032 KB Output is correct
2 Correct 80 ms 53112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 46968 KB Output is correct
2 Correct 110 ms 68472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 30204 KB Output is correct
2 Correct 83 ms 56440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 22912 KB Output is correct
2 Correct 83 ms 65784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 70904 KB Output is correct
2 Correct 123 ms 70776 KB Output is correct