# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
555283 |
2022-04-30T11:15:36 Z |
new_acc |
Strah (COCI18_strah) |
C++14 |
|
209 ms |
40060 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[2002][2002],n,m,fau[N],rep[N],pierw[N],dp[N];
vi g[N];
int Find(int a){
if(fau[a]==a) return a;
return fau[a]=Find(fau[a]);
}
void Union(int a,int b){
fau[Find(a)]=Find(fau[b]);
}
int wzo(int dl){
return dp[dl];
}
int single(int i){
for(int j=1;j<=m;j++){
if(!t[i][j]) pierw[j]=-1;
else{
if(!t[i-1][j]){
int curr=i;
while(t[curr][j]) curr++;
pierw[j]=curr-1;
}
}
if(pierw[j]!=-1) g[pierw[j]].push_back(j);
}
int curr=0,res=0;
for(int j=n;j>=i;j--){
for(auto u:g[j]){
fau[u]=u;
int dl=1;
if(fau[u-1]) dl+=rep[Find(u-1)],curr-=wzo(rep[Find(u-1)]),Union(u,u-1);
if(fau[u+1]) dl+=rep[Find(u+1)],curr-=wzo(rep[Find(u+1)]),Union(u,u+1);
rep[Find(u)]=dl;
curr+=wzo(dl);
}
res+=curr*(j-i+1);
}
for(int j=i;j<=n;j++) g[j].clear();
for(int j=1;j<=m;j++) fau[j]=0,rep[j]=0;
return res;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=m;i++) dp[i]=dp[i-1]+((i*(i+1))>>1);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char a;
cin>>a;
t[i][j]=(a=='.');
}
}
ll res=0;
for(int i=1;i<=n;i++) res+=(ll)single(i);
cout<<res<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23796 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23780 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25428 KB |
Output is correct |
2 |
Correct |
17 ms |
25424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25464 KB |
Output is correct |
2 |
Correct |
17 ms |
25352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
25368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
31232 KB |
Output is correct |
2 |
Correct |
119 ms |
36420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
36964 KB |
Output is correct |
2 |
Correct |
170 ms |
40060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
30612 KB |
Output is correct |
2 |
Correct |
126 ms |
37196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
32420 KB |
Output is correct |
2 |
Incorrect |
155 ms |
38604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
39564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |