# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
555281 |
2022-04-30T11:14:15 Z |
new_acc |
Strah (COCI18_strah) |
C++14 |
|
177 ms |
83748 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[2001][2001],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 |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25488 KB |
Output is correct |
2 |
Correct |
18 ms |
25424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25476 KB |
Output is correct |
2 |
Correct |
16 ms |
25556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
25428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
32296 KB |
Output is correct |
2 |
Correct |
121 ms |
38980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
39436 KB |
Output is correct |
2 |
Correct |
177 ms |
43560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
32276 KB |
Output is correct |
2 |
Correct |
129 ms |
39768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
32644 KB |
Output is correct |
2 |
Incorrect |
160 ms |
41500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
105 ms |
83748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |