QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#126820#2784. Alienssomethingnew#0 1ms4008kbC++204.2kb2023-07-19 00:56:362024-07-04 00:46:00

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:46:00]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4008kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-19 00:56:36]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "aliens.h"
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
ll sq(ll a) {
    return a * a;
}
struct line {
    ll a, b;
    int cnt;
    ll domfrom;
    ll getv(ll x) {
        return a * x + b;
    }
};
struct kht {
    vector<line> kh; // kh[].a * x + kh[].b
    void addline(ll a, ll b, int cnt) {
        while (!kh.empty()) {
            ll xcr = (kh.back().b - b + (a - kh.back().a-1)) / (a - kh.back().a);
            if (xcr < kh.back().domfrom)
                kh.pop_back();
            else
                break;
        }
        ll xcr = 0;
        if (!kh.empty())
            xcr = (kh.back().b - b + (a - kh.back().a-1)) / (a - kh.back().a);
        line ln;
        ln.a = a;
        ln.b = b;
        ln.cnt = cnt;
        ln.domfrom = xcr;
        kh.push_back(ln);
    }
    pair<ll, int> getv(ll x) {
        int l = -1, r = kh.size();
        while (l + 1 < r) {
            int m = l + r >> 1;
            if (kh[m].domfrom < x)
                l = m;
            else
                r = m;
        }
        return {kh[r].getv(x), kh[r].cnt};
    }
};
pair<ll, int> reba(int n, vector<pair<int, int>> opp, ll cc) {
    kht kh;
    vector<int> cnt(n + 1);
    vector<ll> dp(n + 1, 1e18);
    vector<pair<ll, ll>> aboba(n + 1);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        int x = opp[i-1].second + 1;
        ll myval = cc + sq(x);
        aboba[i-1] = {-opp[i-1].first * 2, (dp[i-1] + sq(opp[i-1].first))};
        if (i - 1 != 0)
            aboba[i-1].second -= sq(max(0, opp[i-2].second - opp[i-1].first + 1));
        kh.addline(aboba[i-1].first, aboba[i-1].second, cnt[i-1]);
        pair<ll, int> vlcnt = kh.getv(x);
        dp[i] = vlcnt.first;
        cnt[i] = vlcnt.second + 1;
        dp[i] += myval;
    }
    //cout << dp[n] << ' ' << cnt[n] << ' ' << cc << endl;
    return {dp[n], cnt[n]};
}
pair<ll, int> reba2(int n, vector<pair<int, int>> opp, ll cc) {
    vector<int> cnt(n + 1);
    vector<ll> dp(n + 1, 1e18);
    vector<pair<ll, ll>> aboba(n + 1);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        int x = opp[i-1].second + 1;
        ll myval = cc + sq(x);
        aboba[i-1] = {(dp[i-1] + sq(opp[i-1].first)), -opp[i-1].first * 2};
        if (i - 1 != 0)
            aboba[i-1].first -= sq(max(0, opp[i-2].second - opp[i-1].first + 1));
        for (int j = 0; j < i; ++j) { // (a-b)^2 = a^2+b^2-2ab
            ll vl = aboba[j].first + x * aboba[j].second;
            if (dp[i] > vl) {
                dp[i] = vl;
                cnt[i] = cnt[j] + 1;
            }
        }
        dp[i] += myval;
    }
    //cout << dp[n] << ' ' << cnt[n] << ' ' << cc << endl;
    return {dp[n], cnt[n]};
}
ll take_photos(int n, int m, int k, vector<int> re, vector<int> c) {
    vector<pair<int, int>> sgg(n);
    for (int i = 0; i < n; ++i) {
        sgg[i] = {min(re[i], c[i]), max(re[i], c[i])};
    }
    sort(all(sgg));
    vector<pair<int, int>> bb;
    for (auto [l, r] : sgg) {
        while (!bb.empty() and l == bb.back().first)
            bb.pop_back();
        if (bb.empty() or bb.back().second < r) {
            bb.push_back({l, r});
        }
    }
    sgg = bb;
    n = sgg.size();
    ll l = -1, r = (ll)1e14;
    while (l + 1 < r) {
        ll m = l + r >> 1ll;
        if (reba(n, sgg, m).second > k) {
            l = m;
        } else {
            r = m;
        }
    }
    //cout << r << endl;
    pair<ll, int> val = reba(n, sgg, r);
    return val.first - r * val.second - r * (k-val.second);
}/*
int main() {
    int n, m, k;
    assert(3 == scanf("%d %d %d", &n, &m, &k));
    std::vector<int> r(n), c(n);
    for (int i = 0; i < n; i++) {
        assert(2 == scanf("%d %d", &r[i], &c[i]));
    }
    long long ans = take_photos(n, m, k, r, c);


    printf("%lld\n", ans);
    return 0;
}*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

2 6 2
1 4
4 1

output:

098d134608c94f7413faac591054ee35
56298

result:

wrong answer Wrong answer: output = 56298, expected = 16

Subtask #2:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 0ms
memory: 4008kb

input:

2 2 1
0 0
1 1

output:

098d134608c94f7413faac591054ee35
100000000000083

result:

wrong answer Wrong answer: output = 100000000000083, expected = 4

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%