# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
99599 |
2019-03-05T14:39:10 Z |
win11905 |
Strah (COCI18_strah) |
C++11 |
|
98 ms |
23972 KB |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author win11905
*/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 2e3+5;
class strah {
private:
int n, m;
int dp[N][N];
char inp[N][N];
long f(long x) { return x * (x+1) / 2; }
long ans;
public:
void solve(istream& cin, ostream& cout) {
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> inp[i]+1;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) dp[i][j] = inp[i][j] == '#' ? 0 : (dp[i-1][j]+1);
for(int i = 1; i <= n; ++i) {
dp[i][0] = -1;
stack<int> stk;
stk.emplace(0);
long sum = 0, ret = 0;
for(int j = 1; j <= m; ++j) {
sum += ret;
while(!stk.empty() && dp[i][stk.top()] >= dp[i][j]) {
int v = stk.top(); stk.pop();
long z = f(dp[i][v]) * (j - v) * (v - stk.top());
ret -= z, sum -= z;
sum -= f(dp[i][v]) * f(v - stk.top());
}
sum += f(dp[i][j]) * f(j - stk.top());
ret += f(dp[i][j]) * (j - stk.top());
stk.emplace(j);
ans += sum;
}
}
cout << ans << endl;
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
strah *obj = new strah();
obj->solve(in, out);
}
};
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
Compilation message
strah.cpp: In member function 'void strah::solve(std::istream&, std::ostream&)':
strah.cpp:33:50: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
for(int i = 1; i <= n; ++i) cin >> inp[i]+1;
~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
20096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
19956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
20096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
20120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
20140 KB |
Output is correct |
2 |
Incorrect |
23 ms |
20096 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
21084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
22464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
21520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
20344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
23972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |