답안 #527344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527344 2022-02-17T09:15:25 Z idas Fancy Fence (CEOI20_fancyfence) C++11
0 / 100
1 ms 336 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;
int n;
ll h[N], w[N];

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

    ll lst=h[0], tot=0;
    vi nh, nw;
    FOR(i, 0, n)
    {
        if(h[i]==lst){
            tot+=w[i];
        }
        else{
            nh.pb(lst);
            nw.pb(tot);
            lst=h[i];
            tot=w[i];
        }
    }
    nh.pb(lst);
    nw.pb(tot);

    n=sz(nh);
    FOR(i, 0, n)
    {
        h[i]=nh[i];
        w[i]=nw[i];
    }

//    vector<bool> v(n, false);
//    queue<int> q;
//    if(h[1]<h[0]) q.push(0);
//    FOR(i, 1, n)
//    {
//        if(h[i]>h[i-1] && h[i]>h[i+1]){
//            q.push(i);
//        }
//    }
//
//    while(!q.empty()){
//        int i=q.front();
//        if(v[i]) continue;
//        v[i]=true;
//
//    }

    ll wdt=0, ans=0;
    for(int i=n-1; i>=1; i--){
        wdt+=w[i];
        ll l=h[i]-h[i-1];
        ans+=((2*h[i]-l+1)*l/2%MOD)*((wdt+1)*wdt/2%MOD)%MOD;
    }
    wdt+=w[0];
    ans+=((h[0]+1)*h[0]/2%MOD)*((wdt+1)*wdt/2%MOD)%MOD;

    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 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -