답안 #1036925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036925 2024-07-27T19:48:31 Z ZeroCool Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
21 ms 5724 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define ar array
#define ld long double
 
const int N = 100;
const int X = 10005;
const int B = 400;
const int M = 200;
const int INF = 1e15;
const int LOG = 63;
const int MOD = 1e9 + 7;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int f(int h,int w){
	int a = h * (h + 1) / 2;
	a %= MOD;
	int b = w * (w + 1) / 2;
	b %= MOD;
	return (a * b) % MOD;
}

stack<ar<int, 2> > s;

int ans;

void push(int h,int w){
	int sum = 0;
	
	while(s.size() && s.top()[0] > h){
		sum += s.top()[1];
		sum %= MOD;
		ans += f(sum, s.top()[0]);
		ans %= MOD;
		ans -= f(sum - s.top()[1], s.top()[0]);
		ans = (ans % MOD + MOD) % MOD;
		s.pop();
	}
	ans -= f(sum, h);
	ans = (ans % MOD + MOD) % MOD;
	s.push(ar<int, 2>{h, sum + w});
}

signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;
	int h[n], w[n];
	for(int i = 0;i < n;i++)cin>>h[i];
	for(int i = 0;i < n;i++)cin>>w[i];
	for(int i = 0;i < n;i++)push(h[i], w[i]);
	push(0, 0);
	cout<<ans;
	
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 488 KB Output is correct
3 Correct 9 ms 2068 KB Output is correct
4 Correct 18 ms 4072 KB Output is correct
5 Correct 18 ms 3344 KB Output is correct
6 Correct 15 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 9 ms 2888 KB Output is correct
4 Correct 20 ms 5596 KB Output is correct
5 Correct 21 ms 5640 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 11 ms 2908 KB Output is correct
5 Correct 18 ms 5468 KB Output is correct
6 Correct 18 ms 5460 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 9 ms 2908 KB Output is correct
10 Correct 20 ms 5476 KB Output is correct
11 Correct 17 ms 5460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 472 KB Output is correct
11 Correct 8 ms 1988 KB Output is correct
12 Correct 15 ms 4444 KB Output is correct
13 Correct 14 ms 3596 KB Output is correct
14 Correct 14 ms 3164 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 9 ms 3016 KB Output is correct
18 Correct 17 ms 5468 KB Output is correct
19 Correct 18 ms 5724 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 9 ms 2908 KB Output is correct
23 Correct 19 ms 5468 KB Output is correct
24 Correct 17 ms 5592 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 8 ms 1884 KB Output is correct
33 Correct 8 ms 2140 KB Output is correct
34 Correct 16 ms 3676 KB Output is correct
35 Correct 16 ms 3540 KB Output is correct
36 Correct 17 ms 3924 KB Output is correct
37 Correct 17 ms 3928 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 16 ms 3972 KB Output is correct
40 Correct 17 ms 3932 KB Output is correct
41 Correct 16 ms 3932 KB Output is correct
42 Correct 17 ms 4700 KB Output is correct