Submission #1182192

#TimeUsernameProblemLanguageResultExecution timeMemory
1182192CodeLakVNStrah (COCI18_strah)C++20
110 / 110
102 ms4512 KiB
#include <bits/stdc++.h> using namespace std; #define task "18_strah" #define no "NO" #define yes "YES" #define F first #define S second #define vec vector #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) const int MAX_N = (int)2e3 + 5; int numRow, numCol; string input[MAX_N]; int h[MAX_N], l[MAX_N], r[MAX_N]; void solve() { cin >> numRow >> numCol; FOR(i, 1, numRow) { cin >> input[i]; input[i] = " " + input[i]; } long long ans = 0; FOR(i, 1, numRow) { FOR(j, 1, numCol) h[j] = (input[i][j] == '.' ? h[j] + 1 : 0); stack<int> st; l[1] = 0; st.push(1); FOR(j, 2, numCol) { while (!st.empty() && h[st.top()] > h[j]) st.pop(); l[j] = (st.empty() ? 0 : st.top()); st.push(j); } while (!st.empty()) st.pop(); r[numCol] = numCol + 1; st.push(numCol); FOD(j, numCol - 1, 1) { while (!st.empty() && h[st.top()] >= h[j]) st.pop(); r[j] = (st.empty() ? numCol + 1 : st.top()); st.push(j); } FOR(j, 1, numCol) { int L = j - l[j], R = r[j] - j; long long H = 1LL * h[j] * (h[j] + 1) / 2; long long sumL = 1LL * L * (L + 1) / 2; long long sumR = 1LL * R * (R - 1) / 2; // cout << j << ": " << L << ", " << R << "\n"; ans += 1LL * H * (1LL * R * sumL + 1LL * L * sumR); } } cout << ans; } int32_t main() { if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool multitest = 0; int numTest = 1; if (multitest) cin >> numTest; while (numTest--) { solve(); } return 0; } /* Lak lu theo dieu nhac!!!! */

Compilation message (stderr)

strah.cpp: In function 'int32_t main()':
strah.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
strah.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...