QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#538265#8936. Team Arrangementucup-team133#WA 0ms3780kbC++232.5kb2024-08-31 09:43:552024-08-31 09:43:56

Judging History

This is the latest submission verdict.

  • [2024-08-31 09:43:56]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3780kb
  • [2024-08-31 09:43:55]
  • Submitted

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (std::string_view sep = ""; const auto& e : v) {
        os << std::exchange(sep, " ") << e;
    }
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

using ll = long long;

using namespace std;

const int INF = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<int> l(n), r(n);
    for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
    vector<int> w(n + 1);
    for (int i = 1; i <= n; i++) cin >> w[i];

    vector<int> cnt(n + 1, 0);
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    ranges::sort(ord, {}, [&](int i) { return l[i]; });
    auto check = [&]() -> bool {
        priority_queue<int, vector<int>, greater<int>> pq;
        for (int i = 1, j = 0; i <= n; i++) {
            for (; j < n and l[ord[j]] <= i; j++) pq.emplace(r[ord[j]]);
            if (pq.top() < i) return false;
            for (int k = 0; k < i * cnt[i]; k++) {
                if (pq.empty()) return false;
                pq.pop();
            }
        }
        return true;
    };
    int ans = -INF;
    auto dfs = [&](auto self, int nxt, int rest) -> void {
        if (nxt == 1) {
            cnt[nxt] = rest;
            if (check()) {
                int sum = 0;
                for (int i = 1; i <= n; i++) sum += w[i] * cnt[i];
                ans = max(ans, sum);
            }
            return;
        }
        for (int i = 0; i <= rest / nxt; i++) {
            cnt[nxt] = i;
            self(self, nxt - 1, rest - nxt * i);
        }
    };
    dfs(dfs, n, n);

    if (ans == -INF) {
        cout << "impossible\n";
    } else {
        cout << ans << "\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

impossible

result:

wrong answer 1st lines differ - expected: '6', found: 'impossible'