Submission #303339

#TimeUsernameProblemLanguageResultExecution timeMemory
303339Ruxandra985Fancy Fence (CEOI20_fancyfence)C++14
100 / 100
42 ms5368 KiB
#include <bits/stdc++.h> #define MOD 1000000007 #define DIMN 100010 using namespace std; long long h[DIMN] , w[DIMN] , st[DIMN]; long long spw[DIMN]; long long rectangles (long long x , long long y){ x %= MOD; y %= MOD; return ( ( (x * (x + 1) / 2)%MOD ) * ( (y * (y + 1) / 2)%MOD ) )%MOD; } int main() { FILE *fin = stdin; FILE *fout = stdout; long long n , i , elem = 0; long long sol = 0 , lat; fscanf (fin,"%lld",&n); for (i = 1 ; i <= n ; i++) fscanf (fin,"%lld",&h[i]); for (i = 1 ; i <= n ; i++){ fscanf (fin,"%lld",&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 (max(h[st[elem - 1]] , h[i]) , lat))%MOD; elem--; } st[++elem] = i; } sol = ((sol + MOD)%MOD); fprintf (fout,"%lld",sol); return 0; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:21:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     fscanf (fin,"%lld",&n);
      |     ~~~~~~~^~~~~~~~~~~~~~~
fancyfence.cpp:23:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         fscanf (fin,"%lld",&h[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~
fancyfence.cpp:25:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         fscanf (fin,"%lld",&w[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...