Submission #291192

# Submission time Handle Problem Language Result Execution time Memory
291192 2020-09-04T21:02:01 Z TadijaSebez Fancy Fence (CEOI20_fancyfence) C++11
100 / 100
43 ms 1916 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
void ckadd(int&x,int y){x=add(x,y);}
int sub(int x,int y){x-=y;return x<0?x+mod:x;}
void cksub(int&x,int y){x=sub(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
int C2(int x){return (ll)x*(x+1)/2%mod;}
const int N=100050;
int h[N],w[N],H[N],W[N],c;
int main(){
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++)scanf("%i",&h[i]);
	for(int i=1;i<=n;i++)scanf("%i",&w[i]);
	int sum=0,ans=0;
	for(int i=1;i<=n;i++){
		int sum_w=0;
		while(c>0&&H[c]>=h[i]){
			ckadd(sum_w,W[c]);
			cksub(sum,mul(C2(H[c]),W[c]));
			c--;
		}
		ckadd(ans,mul(w[i],add(sum,mul(sum_w,C2(h[i])))));
		ckadd(ans,mul(C2(w[i]),C2(h[i])));
		ckadd(sum_w,w[i]);
		ckadd(sum,mul(sum_w,C2(h[i])));
		c++;H[c]=h[i];W[c]=sum_w;
	}
	printf("%i\n",ans);
	return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%i",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:16:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i=1;i<=n;i++)scanf("%i",&h[i]);
      |                       ~~~~~^~~~~~~~~~~~
fancyfence.cpp:17:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  for(int i=1;i<=n;i++)scanf("%i",&w[i]);
      |                       ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
4 Correct 31 ms 1144 KB Output is correct
5 Correct 32 ms 1148 KB Output is correct
6 Correct 30 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 20 ms 768 KB Output is correct
4 Correct 36 ms 1144 KB Output is correct
5 Correct 38 ms 1148 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 19 ms 768 KB Output is correct
5 Correct 39 ms 1148 KB Output is correct
6 Correct 39 ms 1152 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 19 ms 896 KB Output is correct
10 Correct 36 ms 1916 KB Output is correct
11 Correct 36 ms 1912 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 16 ms 768 KB Output is correct
12 Correct 31 ms 1152 KB Output is correct
13 Correct 32 ms 1144 KB Output is correct
14 Correct 31 ms 1144 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 18 ms 768 KB Output is correct
18 Correct 36 ms 1144 KB Output is correct
19 Correct 37 ms 1152 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 20 ms 896 KB Output is correct
23 Correct 39 ms 1916 KB Output is correct
24 Correct 38 ms 1912 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 18 ms 768 KB Output is correct
33 Correct 20 ms 768 KB Output is correct
34 Correct 37 ms 1144 KB Output is correct
35 Correct 35 ms 1152 KB Output is correct
36 Correct 43 ms 1144 KB Output is correct
37 Correct 38 ms 1144 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 38 ms 1144 KB Output is correct
40 Correct 38 ms 1144 KB Output is correct
41 Correct 38 ms 1144 KB Output is correct
42 Correct 37 ms 1528 KB Output is correct