# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
503354 |
2022-01-07T17:24:12 Z |
inksamurai |
Strah (COCI18_strah) |
C++17 |
|
149 ms |
31856 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
void print(){
cout<<"\n";
}
template<class te,class ...ti>
void print(const te&v, const ti&...nv) {
cout<<v;
if(sizeof...(nv)){
cout<<" ";
print(nv...);
}
}
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
using tupiii=tuple<int,int,int>;
int tria(int x){
return (x*(x+1))/2;
}
void slv(){
int h,w;
cin>>h>>w;
vec(vi) a(h+1,vi(w));
rep(i,h){
rep(j,w){
char ch;
cin>>ch;
a[i][j]=(ch=='.');
}
}
h++;
vec(vi) dwn(h,vi(w));
drep(i,h){
rep(j,w){
if(!a[i][j]) dwn[i][j]=i;
else dwn[i][j]=dwn[i+1][j];
}
}
ll ans=0;
drep(i,h-1){
vec(tupiii) stk;
ll _fsum=0,_sum=0;
drep(j,w){
if(!a[i][j]){
stk.clear();
_fsum=0;
_sum=0;
}else{
int lo=dwn[i][j],cnt=1,sj=j;
while(sz(stk)){
auto [plo,pcnt,psj]=stk.back();
if(plo<lo){
break;
}
stk.pop_back();
cnt+=pcnt;
ll x=tria(lo-i),y=tria(plo-i);
_sum-=y*pcnt;
_sum+=x*pcnt;
_fsum-=y*(psj-pcnt*j);
_fsum+=x*(psj-pcnt*j);
sj+=psj;
}
_sum+=tria(lo-i);
_fsum+=_sum;
ans+=_fsum;
stk.pb({lo,cnt,sj});
}
}
}
print(ans,'\n');
}
int main(){
_3qplfh5;
int t=1;
// cin>>t;
rep(cs,t)
slv();
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
972 KB |
Output is correct |
2 |
Correct |
4 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
972 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
972 KB |
Output is correct |
2 |
Correct |
3 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
8528 KB |
Output is correct |
2 |
Correct |
81 ms |
19176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
19780 KB |
Output is correct |
2 |
Correct |
125 ms |
29148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
12580 KB |
Output is correct |
2 |
Correct |
98 ms |
20908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2504 KB |
Output is correct |
2 |
Correct |
98 ms |
23364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
31780 KB |
Output is correct |
2 |
Correct |
149 ms |
31856 KB |
Output is correct |