답안 #528080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528080 2022-02-19T07:09:29 Z idas Fancy Fence (CEOI20_fancyfence) C++11
100 / 100
44 ms 5380 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=1e5+10;
ll h[N], w[N];
int n, par[N];
bool v[N];

int fnd(int u)
{
    return par[u]=par[u]==u?u:fnd(par[u]);
}

void mrg(int a, int b)
{
    a=fnd(a); b=fnd(b);
    if(a==b) return;
    w[a]+=w[b];
    w[a]%=MOD;
    par[b]=a;
}

ll eq(ll x)
{
    return (x+1)*x/2%MOD;
}

ll eval(ll x, ll y)
{
    return eq(x)*eq(y)%MOD;
}

bool cmp(int a, int b)
{
    return h[a]>h[b];
}

int main()
{
    setIO();
    cin >> n;
    vi idx;
    FOR(i, 0, n) cin >> h[i], idx.pb(i);
    FOR(i, 0, n) cin >> w[i];

    sort(all(idx), cmp);

    FOR(i, 0, n) par[i]=i;

    ll ans=0;
    for(auto i : idx){
        v[i]=true;
        ll x=0, y=0;
        if(i!=0){
            if(v[i-1]){
                x=w[fnd(i-1)];
            }
        }
        if(i!=n-1){
            if(v[i+1]){
                y=w[fnd(i+1)];
            }
        }

        ans+=eval(h[i], w[i]+x+y);
        ans-=eval(h[i], x);
        ans-=eval(h[i], y);
        while(ans<0) ans+=MOD;
        ans%=MOD;

        if(x!=0) mrg(i, i-1);
        if(y!=0) mrg(i, i+1);
    }

    cout << ans;
}

Compilation message

fancyfence.cpp: In function 'void setIO(std::string)':
fancyfence.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 12 ms 2260 KB Output is correct
4 Correct 28 ms 4012 KB Output is correct
5 Correct 26 ms 4040 KB Output is correct
6 Correct 23 ms 3972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 708 KB Output is correct
3 Correct 15 ms 2632 KB Output is correct
4 Correct 29 ms 4808 KB Output is correct
5 Correct 30 ms 4856 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 840 KB Output is correct
4 Correct 13 ms 2636 KB Output is correct
5 Correct 29 ms 4708 KB Output is correct
6 Correct 29 ms 4876 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 14 ms 2632 KB Output is correct
10 Correct 27 ms 4676 KB Output is correct
11 Correct 29 ms 4692 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 14 ms 2184 KB Output is correct
12 Correct 30 ms 4056 KB Output is correct
13 Correct 24 ms 4032 KB Output is correct
14 Correct 21 ms 4036 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 756 KB Output is correct
17 Correct 14 ms 2628 KB Output is correct
18 Correct 26 ms 4820 KB Output is correct
19 Correct 36 ms 4928 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 18 ms 2640 KB Output is correct
23 Correct 28 ms 4608 KB Output is correct
24 Correct 30 ms 4808 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 4 ms 720 KB Output is correct
31 Correct 4 ms 844 KB Output is correct
32 Correct 16 ms 2492 KB Output is correct
33 Correct 18 ms 2612 KB Output is correct
34 Correct 38 ms 4536 KB Output is correct
35 Correct 30 ms 4624 KB Output is correct
36 Correct 38 ms 4716 KB Output is correct
37 Correct 44 ms 4808 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 39 ms 4728 KB Output is correct
40 Correct 33 ms 4820 KB Output is correct
41 Correct 43 ms 4888 KB Output is correct
42 Correct 31 ms 5380 KB Output is correct