Submission #151212

# Submission time Handle Problem Language Result Execution time Memory
151212 2019-09-02T08:15:03 Z Ruxandra985 Strah (COCI18_strah) C++14
0 / 110
167 ms 29944 KB
#include <cstdio>

using namespace std;
int a[2010][2010],jos[2010][2010],st[2010];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n,m,i,j,len,elem;
    char c;
    long long sol=0;
    fscanf (fin,"%d%d",&n,&m);
    for (i=1;i<=n;i++){
        fgetc (fin);
        for (j=1;j<=m;j++){
            c=fgetc (fin);
            if (c=='#')
                a[i][j] = 1; /// blocat
        }
    }
    /// precalculare jos
    for (i=n;i;i--){
        for (j=1;j<=m;j++){
            if (a[i][j] == 0) /// cate sunt in jos
                jos[i][j] = jos[i+1][j] + 1;
            else jos[i][j] = 0;
        }
    }
    /// fixezi o linie
    sol = 0;
    for (i=1;i<=n;i++){
        elem = 0;
        st[0] = 0;
        for (j=1;j<=m;j++){
            while (elem && jos[i][st[elem]] >= jos[i][j])
                elem--;
            st[++elem] = j;
            /// j are influenta in intervalul st[elem-1] + 1 .. st[elem]
            len = st[elem] - st[elem-1];
            sol = sol + (long long)(jos[i][j] * (jos[i][j] + 1) / 2) * (len * (len+1) / 2);
        }
        elem = 0;
        st[0] = m+1;
        for (j=m;j;j--){
            while (elem && jos[i][st[elem]] >= jos[i][j])
                elem--;
            st[++elem] = j;
            /// j are influenta in intervalul st[elem-1] + 1 .. st[elem]
            len = st[elem-1] - st[elem];
            sol = sol + (long long)(jos[i][j] * (jos[i][j] + 1) / 2) * (len * (len+1) / 2);
        }
        /// ai numarat secventele egale de doua ori
        len = 0;
        for (j=1;j<=m;j++){
            if (jos[i][j] == jos[i][j-1])
                len++;
            else
                len = 1;
            sol = sol - (long long)(jos[i][j] * (jos[i][j] + 1) / 2) * (len * (len+1) / 2);
        }
        //printf ("%lld\n",sol);
    }
    fprintf (fout,"%lld",sol);
    return 0;
}

Compilation message

strah.cpp: In function 'int main()':
strah.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Incorrect 8 ms 3448 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 14564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 135 ms 23676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 15224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 17272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 29944 KB Output isn't correct
2 Halted 0 ms 0 KB -