Submission #303312

# Submission time Handle Problem Language Result Execution time Memory
303312 2020-09-20T07:49:48 Z Ruxandra985 Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define MOD 1000000007
#define DIMN 100010
using namespace std;

int h[DIMN] , w[DIMN] , st[DIMN];
long long spw[DIMN];

long long rectangles (int x , int y){

    return (((1LL * x * (x + 1) / 2))%MOD * ((1LL * y * (y + 1) / 2)%MOD))%MOD;

}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , i , elem = 0;
    long long sol = 0 , lat;
    fscanf (fin,"%d",&n);
    for (i = 1 ; i <= n ; i++)
        fscanf (fin,"%d",&h[i]);
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&w[i]);

        spw[i] = w[i] + spw[i - 1];

    }

    h[n + 1] = 0; /// turn fictiv inaltime ft mica
    w[n + 1] = 0;
    spw[n + 1] = spw[n];
    n++;

    elem = 0;
    for (i = 1 ; i <= n ; i++){

        while (elem && h[i] < h[st[elem]]){

            /// i il scoate pe st[elem]
            lat = spw[i - 1] - spw[st[elem] - 1];

            sol = (sol + rectangles(h[st[elem]] , lat) - rectangles (h[st[elem - 1]] , lat))%MOD;

            elem--;
        }

        st[++elem] = i;


    }

    sol = ((sol + MOD)%MOD);

    fprintf (fout,"%lld",sol);
    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:20:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     fscanf (fin,"%d",&n);
      |     ~~~~~~~^~~~~~~~~~~~~
fancyfence.cpp:22:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         fscanf (fin,"%d",&h[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~
fancyfence.cpp:24:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         fscanf (fin,"%d",&w[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct