이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
bool cmp(const ii &l,const ii &r) {
if(l.st < r.st) return true;
if(l.st > r.st) return false;
return l.nd < r.nd;
}
int les(int x){
return (x * (x+1))/2;
}
void solve(){
int n,m; cin >> n >> m;
int rel[n+1][m+1];
for(int i=1; i<=m; i++) rel[0][i]=0;
for(int i=1; i<=n; i++){
string s; cin >> s;
for(int j=1; j<=m; j++){
if(s[j-1]=='#') rel[i][j] = 0;
else rel[i][j] = rel[i-1][j]+1;
//cerr << rel[i][j] << " ";
}
//cerr << endl;
}
int pref[n+1]; pref[0]=0;
ii cur[n+1]; cur[0]={0, 0};
int add[n+1]; add[0]=0;
int end, ans=0;
for(int k=1; k<=n; k++){
end=0;
for(int i=1; i<=m; i++){
end = lower_bound(cur, cur+end+1, mp(rel[k][i], i)) - cur;
cur[end] = mp(rel[k][i], i);
add[end] = add[end-1] + (les(cur[end].st) * (cur[end].nd-cur[end-1].nd));
pref[end] = pref[end-1] + (add[end-1] * (cur[end].nd - cur[end-1].nd)) + (les(cur[end].st) * les(cur[end].nd - cur[end-1].nd));
cerr << end spc add[end] spc pref[end] spc pref[end-1] << " :: ";
ans += pref[end];
}
cerr << endl;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |