QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#126802#2784. Alienssomethingnew#Compile Error//C++202.5kb2023-07-19 00:19:172024-07-04 00:45:31

Judging History

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

  • [2024-07-04 00:45:31]
  • 评测
  • [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:19:17]
  • 提交

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;
}
pair<ll, int> reba(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) {
        aboba[i-1] = {(dp[i-1] + sq(opp[i-1].first)), -opp[i-1].first * 2};
        for (int j = 0; j < i; ++j) { // (a-b)^2 = a^2+b^2-2ab
            int x = opp[i-1].second + 1;
            ll vl = aboba[j].first + sq(x) + x * aboba[j].second + cc;
            //cout << aboba[j].first << ' ' << sq(x) << ' ' << x * aboba[j].second << ' ' << vl - cc << endl;
            if (i != 1)
                vl -= sq(max(0, opp[i-2].second - opp[i-1].first  + 1));
            if (dp[i] > vl or (dp[i] == vl and cnt[i] > cnt[j] + 1)) {
                dp[i] = vl;
                cnt[i] = cnt[j] + 1;
            }
        }
    }
   // cout << dp[n] << ' ' << cnt[n] << 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 << l << 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;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:76:5: error: ‘assert’ was not declared in this scope
   76 |     assert(3 == scanf("%d %d %d", &n, &m, &k));
      |     ^~~~~~
answer.code:17:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
   16 | #include "aliens.h"
  +++ |+#include <cassert>
   17 | #define all(x) x.begin(), x.end()