QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630124#8936. Team ArrangementsupepapupuWA 1ms3620kbC++201.5kb2024-10-11 16:37:132024-10-11 16:37:13

Judging History

This is the latest submission verdict.

  • [2024-10-11 16:37:13]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3620kb
  • [2024-10-11 16:37:13]
  • Submitted

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

int n, w[N];
vector<pii> seg;
vector<int> stk;
int ans = INF;

void dfs(int lst, int tot) {
    if (tot > n) return;
    if (tot == n) {
        int i = 0, res = 0;
        priority_queue<int, vector<int>, greater<int>> Q;
        for (int sz: stk) {
            while (i < n && seg[i].x <= sz) {
                Q.push(seg[i++].y);
            }
            for (int i = 0; i < sz; ++i) {
                if (!Q.size()) {
                    res = INF;
                    break;
                }
                int t = Q.top(); Q.pop();
                if (t < sz) {
                    res = INF;
                    break;
                }
            }
            res += w[sz];
        }
        ans = min(ans, res);
        return;
    }
    for (int j = lst; j + tot <= n; ++j) {
        stk.emplace_back(j);
        dfs(j, tot + j);
        stk.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    seg.resize(n);
    for (int i = 0; i < n; ++i) cin >> seg[i].x >> seg[i].y;
    sort(seg.begin(), seg.end());
    for (int i = 1; i <= n; ++i) cin >> w[i];
    dfs(1, 0);
    if (ans == INF) cout << "impossible\n";
    else cout << ans << el;
}

詳細信息

Test #1:

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

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: 3500kb

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: 3620kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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: 1ms
memory: 3568kb

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:

4

result:

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