QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637526 | #8936. Team Arrangement | ucup-team173# | WA | 0ms | 4024kb | C++20 | 1.8kb | 2024-10-13 13:12:37 | 2024-10-13 13:12:37 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve() {
int n;
n = 60;
cin >> n;
vector<vector<int>> tt(n + 1);
vector<int> w(n + 1);
for (int i = 1; i <= n; i++) {
int l, r;
l = 1, r = n;
cin >> l >> r;
tt[l].push_back(r);
}
for (int i = 1; i <= n; i++) {
w[i] = 0;
cin >> w[i];
}
vector<int> q(n + 2);
int ans = -1e9;
auto dfs = [&](auto self, int sum, int now, int res) {
if (sum == 0) {
ans = max(ans, res);
return;
}
if (now == n + 1 || sum < now) return ;
vector<int> rq = q;
for (auto o : tt[now]) q[o]++;
self(self, sum, now + 1, res);
int ttt = now;
// cout << now << '\n';
// for (auto cnt : q) cout << cnt << ' ';
// cout << '\n';
for (int t = 1; t * now <= sum; t++) {
res += w[now];
for (int j = 1; j <= now; j++) {
while(ttt <= n && !q[ttt]) ttt++;
q[ttt]--;
}
// cout << now << ' ' << t << ' ' << ttt << ' ' << res << '\n';
if (ttt > n) {
break;
}
if (sum == t * now || sum - t * now >= now + 1) {
self(self, sum - t * now, now + 1, res);
}
res -= w[now];
}
q = rq;
};
// for (auto o : tt[1]) q[o]++;
dfs(dfs, n, 1, 0);
if (ans <= -1e9) {
cout << "Impossible\n";
} else {
cout << ans << '\n';
}
cerr << 1. * clock() / CLOCKS_PER_SEC << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: 3836kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 4024kb
input:
2 1 1 2 2 1 1
output:
Impossible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'Impossible'