#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> B;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=2020;
int n,m,R[N][N];
char s[N][N];
ll F(ll x) {
return x*(x+1)/2;
}
int main() {
scanf("%d%d",&n,&m);
rep(i,0,n) {
scanf("%s",s+i);
}
rep(i,0,n) {
int p=0;
rep(j,0,m) {
if (s[i][j]=='#') p=j+1;
else R[i][j]=p;
}
}
ll ans=0;
rep(j,0,m) {
vector<array<int,3>> stk;
ll coeff=0,dec=0;
rep(i,0,n) {
if (s[i][j]=='#') {
coeff=0; dec=0;
stk.clear();
continue;
}
int len=j-R[i][j]+1,to=i;
while (SZ(stk)&&stk.back()[2]>=len) {
coeff-=(stk.back()[1]-stk.back()[0]+1)*1ll*F(stk.back()[2]);
dec-=(F(stk.back()[1])-F(stk.back()[0]-1))*1ll*F(stk.back()[2]);
to=stk.back()[0];
stk.pop_back();
}
coeff+=(i-to+1)*1ll*F(len);
dec+=(F(i)-F(to-1))*1ll*F(len);
ans+=(i+1)*coeff-dec;
stk.pb({to,i,len});
}
}
printf("%lld",ans);
}
Compilation message
strah.cpp: In function 'int main()':
strah.cpp:35:11: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[2020]' [-Wformat=]
35 | scanf("%s",s+i);
| ~^ ~~~
| | |
| | char (*)[2020]
| char*
strah.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
strah.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%s",s+i);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
13912 KB |
Output is correct |
2 |
Correct |
42 ms |
19352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
17236 KB |
Output is correct |
2 |
Correct |
66 ms |
23316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
14428 KB |
Output is correct |
2 |
Correct |
46 ms |
21628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19304 KB |
Output is correct |
2 |
Correct |
51 ms |
21992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
24156 KB |
Output is correct |
2 |
Correct |
72 ms |
24292 KB |
Output is correct |