Submission #855772

# Submission time Handle Problem Language Result Execution time Memory
855772 2023-10-01T18:51:33 Z vjudge1 Strah (COCI18_strah) C++17
55 / 110
37 ms 10996 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 100000
using namespace std; 
const int mod=1000000007ll;
bool st1[300][10][300],st2[300][10][300];

bool q1(int i,int j,int len){
    int k=__lg(len);
    //cerr<<i<<" "<<k<<" "<<j<<" "<<j+len-(1<<k)<<"\n";
    return st1[i][k][j]||st1[i][k][j+len-(1<<k)];
}
bool q2(int i,int j,int len){
    int k=__lg(len);
    return st2[i][k][j]||st2[i][k][j+len-(1<<k)];
}

void solve(){
    int n,m;
    cin>>n>>m;
    string grid[n];
    for(int i=0;i<n;i++){
        cin>>grid[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            st1[i][0][j]=(grid[i][j]=='#');
            //cerr<<st1[i][0][j]<<" ";
        }//cerr<<"\n";
        for(int j=1;j<=__lg(m);j++){
            for(int k=0;k<m-(1<<(j-1));k++){
                st1[i][j][k]=st1[i][j-1][k]||st1[i][j-1][k+(1<<(j-1))];
                //cerr<<st1[i][j][k]<<" ";
                //if(!i&&j==1&&!k)cerr<<st1[i][j][k]<<" "<<st1[i][j-1][k]<<" "<<st1[i][j-1][k+(1<<(j-1))]<<"\n";
            }//cerr<<"\n";
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            st2[i][0][j]=(grid[j][i]=='#');
            //cerr<<st2[i][0][j]<<" ";
        }//cerr<<"\n";
        for(int j=1;j<=__lg(n);j++){
            for(int k=0;k<n-(1<<(j-1));k++){
                st2[i][j][k]=st2[i][j-1][k]||st2[i][j-1][k+(1<<(j-1))];
                //cerr<<st2[i][j][k]<<" ";
            }//cerr<<"\n";
        }
    }
    /*
    int q;
    cin>>q;
    while(q--){
        int i,j,len;
        cin>>i>>j>>len;
        cerr<<q2(i,j,len)<<"\n";
    }
    */
    //cerr<<st1[0][1][0]<<"\n";
    //cerr<<q1(0,0,2)<<"\n";
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int most=m-j;
            //cerr<<i<<" "<<j<<"\n\n";
            for(int k=0;k+i<n;k++){
                while(most&&q1(i+k,j,most))most--;
                if(!most)break;
                ans+=(k+1)*most*(most+1)/2;
                //err<<i+k<<" "<<k<<" "<<most<<"\n";
            }
            //cerr<<"\n\n";
            /*
            cerr<<ans<<"\n\n";
            cerr<<"\n";
            most=n-i;
            for(int k=0;k+j<m;k++){
                while(most&&q2(j+k,i,most))most--;
                cerr<<j+k<<" "<<k<<" "<<most<<"\n";
                if(!most)break;
                ans+=(k+1)*most;
            }
            cerr<<"\n\n";
            */
        }
    }
    cout<<ans<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2136 KB Output is correct
2 Correct 27 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2136 KB Output is correct
2 Correct 26 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2140 KB Output is correct
2 Correct 26 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 4444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 7516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 5724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 10996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -