Submission #1329690

#TimeUsernameProblemLanguageResultExecution timeMemory
1329690nguyenkhanghuyFancy Fence (CEOI20_fancyfence)C++20
30 / 100
17 ms1960 KiB

# include <bits/stdc++.h>
using namespace std;

# define ld long double
# define int long long
# define SNC cin.tie(0) -> ios::sync_with_stdio(false)
# define For(i, a, b) for (int i = a; i <= b; i++)
# define Rep(i, b, a) for (int i = b; i >= a; i--)
# define Fa(i, x) for (auto i : x)
# define ii pair<int, int>
# define iii pair<int, ii>
# define iv pair<ii, ii>
# define f first
# define s second
# define all(x) x.begin(), x.end()
# define sp(x) setprecision(x) << fixed
# define name "FENCE"
# define spc " "
# define endl "\n"

void readfile(){
    if (fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }
}

const int mod = 1e9 + 7;
const int inf = 1e18;
const int N = 2e5 + 10;
typedef int arr[N];
typedef vector<int> vi;
typedef vector<ii> vii;

int n;
arr h, w;

void Input(){
    cin >> n;
    For(i, 1, n)
    cin >> h[i];
    For(i, 1, n)
    cin >> w[i];
}

int add(int a, int b){
    return (a % mod + b % mod) % mod;
}

int sub(int a, int b){
    return (a % mod - b % mod + mod) % mod;
}

int mul(int a, int b){
    return ((a % mod) * (b % mod)) % mod;
}

int div(int a){
    int b = (a + 1);
    if (b % 2 == 0)
        b /= 2;
    else a /= 2;
    return mul(a, b);
}

namespace sub1{
    bool approved(){
        return n <= 1000;
    }

    arr _h;

    void Solve(){

    }
}

namespace sub2{
    bool approved(){
        For(i, 1, n)
        if (h[i] != h[1])
            return false;
        return true;
    }

    void Solve(){
        int W = 0, H = h[1];
        For(i, 1, n)
            W += w[i];
        cout << mul(div(H), div(W)) % mod;
    }
}

namespace sub3{
    bool approved(){
        For(i, 2, n)
        if (h[i - 1] > h[i])
            return false;
        return true;
    }

    arr pre;
    int ans = 0;

    void Solve(){
        int W = 0;
        Rep(i, n, 1)
            W += w[i];
        int sum = 0;
        For(i, 1, n){
//            (ans += (h[i] * (h[i] + 1) / 2) * (W * (W + 1) / 2));
            ans = add(ans, mul(div(h[i]), div(W)));
            sum = W;
            W -= w[i];
//            (ans -= (h[i - 1] * (h[i - 1] + 1) / 2) * (sum * (sum + 1) / 2));
            ans = sub(ans, mul(div(h[i - 1]), div(sum)));
        }
        cout << ans;
    }
}

void Solve(){
	if (sub2::approved())
        sub2::Solve();
    else if (sub3::approved())
        sub3::Solve();
}

signed main(){
    SNC;
    readfile();
    Input();
    Solve();
    return 0;
}

Compilation message (stderr)

fancyfence.cpp: In function 'void readfile()':
fancyfence.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...