답안 #389981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389981 2021-04-15T03:10:45 Z talant117408 Fancy Fence (CEOI20_fancyfence) C++17
43 / 100
86 ms 3708 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 1e9+7;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

const int N = 1e5+7;
ll h[N], w[N], dp[N];
int n;

bool subtask2() {
	return false;
}

bool subtask3() {
	int flag = 1;
	for (int i = 1; i <= n; i++) {
		if (h[i] > 2) flag = 0;
	}
	return flag;
}

bool subtask4() {
	int flag = 1;
	for (int i = 2; i <= n; i++) {
		if (h[i] != h[i-1]) flag = 0;
	}
	return flag;
}

bool subtask5() {
	int flag = 1;
	for (int i = 2; i <= n; i++) {
		if (h[i] < h[i-1]) flag = 0;
	}
	return flag;
}

int main() {
	do_not_disturb
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}
	
	if (subtask2()) {
		
	}
	else if (subtask3()) {
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ans += w[i];
		}
		ans = mult(ans, mult(ans+1, binpow(2, mod-2)));
		ll cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (h[i] == 2) {
				cnt += w[i];
			}
			else {
				ans = add(ans, mult(cnt, cnt+1));
				cnt = 0;
			}
		}
		ans = add(ans, mult(cnt, cnt+1));
		cout << ans;
	}
	else if (subtask4()) {
		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += w[i];
		}
		cout << mult(mult(mult(sum, sum+1), mult(h[1], h[1]+1)), binpow(4, mod-2));
	}
	else if (subtask5()) {
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ans = add(ans, mult(mult(mult(w[i], w[i]+1), mult(h[i], h[i]+1)), binpow(4, mod-2)));
		}
		ll sum = 0;
		for (int i = 1; i <= n; i++) {
			ans = add(ans, mult(sum, w[i]));
			sum = add(sum, mult(mult(h[i], mult(h[i]+1, binpow(2, mod-2))), w[i]));
		}
		cout << ans;
	}
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 10 ms 1100 KB Output is correct
4 Correct 19 ms 1972 KB Output is correct
5 Correct 23 ms 1888 KB Output is correct
6 Correct 18 ms 1780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 12 ms 1080 KB Output is correct
4 Correct 22 ms 1844 KB Output is correct
5 Correct 26 ms 1880 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 12 ms 1088 KB Output is correct
5 Correct 25 ms 1832 KB Output is correct
6 Correct 26 ms 1832 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 9 ms 656 KB Output is correct
9 Correct 44 ms 1996 KB Output is correct
10 Correct 84 ms 3708 KB Output is correct
11 Correct 86 ms 3692 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct