Submission #305099

#TimeUsernameProblemLanguageResultExecution timeMemory
305099phathnvStrah (COCI18_strah)C++11
110 / 110
123 ms70904 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...