답안 #593211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593211 2022-07-10T15:13:45 Z OttoTheDino Sightseeing in Kyoto (JOI22_kyoto) C++17
0 / 100
1 ms 212 KB
//one of the coolest problems i've ever seen
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (ll i = s; i <= e; ++i)
#define pb(u)                       push_back(u)
#define len(a)                      (ll)a.size()
typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll h, w, x = 0; cin >> h >> w;
    ll a[h+1], b[w+1];
    rep (i,1,h) cin >> a[i];
    rep (i,1,w) cin >> b[i];
    vector<ll> ha, hb;
    ha.pb(1), hb.pb(1);
    rep (i,2,h) {
        while (true) {
            ll n = len(ha);
            if (n==1 || ((a[ha[n-1]]-a[ha[n-2]])*(i-ha[n-1])<(a[i]-a[ha[n-1]])*(ha[n-1]-ha[n-2]))) break;
            ha.pop_back();
        }
        ha.pb(i);
    }
    rep (i,2,w) {
        while (true) {
            ll n = len(hb);
            if (n==1 || ((b[hb[n-1]]-b[hb[n-2]])*(i-hb[n-1])<(b[i]-b[hb[n-1]])*(hb[n-1]-hb[n-2]))) break;
            hb.pop_back();
        }
        hb.pb(i);
    }
    while (true) {
        ll n = len(ha), m = len(hb);
        if (max(n,m)<2) break;
        if (m==1 || (a[ha[n-1]]-a[ha[n-2]])*(hb[m-1]-hb[m-2])<=(b[hb[m-1]]-b[hb[m-2]])*(ha[n-1]-ha[n-2])) {
            x += a[ha[n-1]] * (hb[m-1]-hb[m-2]);
            hb.pop_back();
        }
        else {
            x += b[hb[m-1]] * (ha[n-1]-ha[n-2]);
            ha.pop_back();
        }
    }
    cout << x << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -