Submission #1334503

#TimeUsernameProblemLanguageResultExecution timeMemory
1334503nhan0123456Fancy Fence (CEOI20_fancyfence)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
bool memory1;

typedef long long ll;
typedef unsigned long long ull;
typedef double dbe;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vii;

#define openFile(name) freopen((name ".inp"), "r", stdin), freopen((name ".out"), "w", stdout)
#define FOR(i, a, b, x) for (ll i = (a); i <= (b); i += (x))
#define ROF(i, a, b, x) for (ll i = (a); i >= (b); i += (x))
#define fi first
#define se second
#define MASK(x) (1LL << (x))
#define getBit(mask, i) (((mask) >> (i)) & 1LL)
#define BitOn(mask) (__builtin_popcountll(mask))

const int maxN = 1e5 + 5;
//const ll maxBit = MASK(8) + 2;
const ll LOG = 20;
const ll INF18 = 1e18;
const int INF9 = 1e9;
//const ll INF3f = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

//////////////////////////////////////////////
/////////////////nhan0123456//////////////////
//////////////////////////////////////////////

ll n;
pll a[maxN];

ll powMod(ll a, ll b, const ll c) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) ans = ans * a % c;
        a = a * a % c;
        b = b >> 1;
    }
    return ans;
}

namespace sub4 {
    bool check() {
        FOR (i, 1, n, 1) if (a[i].fi != a[1].fi) return false;
        return true;
    }
    ll Solve() {
        ll sumW = 0;
        FOR (i, 1, n, 1) (sumW += a[i].se) %= MOD;
        /*
            n * n - 1 / 2
            1 1 1 1
            2 2 2 2
            9
            h = 1
            A = w * w - 1 / 2;
            h = 2 ->
                A2 = A + A + A = 3 * A
                A3 = A2 + A2 + A2 = 3 * A2 = 3^2 * A1
        */
        ll t = (sumW + sumW * (sumW - 1) % MOD * powMod(2, MOD - 2, MOD)) % MOD;
        return t * powMod(3, a[1].fi - 1, MOD) % MOD;
    }
}

void input() {
    /*
        dem so hcn
        hi.. wi
    */
    cin >> n;
    FOR (i, 1, n, 1) cin >> a[i].fi;
    FOR (i, 1, n, 1) cin >> a[i].se;
    if (sub4::check()) cout << sub4::Solve();

}

int main() {
    //openFile("temp");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    input();

    //bool memory2;
    //cerr << "\n\n\nTime: "<< 1000.0 * clock() / CLOCKS_PER_SEC << " ms";
    //cerr << "\n\n\nMemory: "<< abs(&memory1 - &memory2) * 1.0 / MASK(20) <<" MB";

    return 0;
}
#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...