QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568845 | #8936. Team Arrangement | xuanbac05 | WA | 2ms | 14172kb | C++17 | 2.3kb | 2024-09-16 18:47:48 | 2024-09-16 18:47:48 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int w[mxN];
int open[mxN];
int close[mxN];
pair<int, int> a[mxN];
int cnt[67][67];
int pre[67][67];
long long dp[67][67][67];
int getsum(int x, int y, int u, int v) {
if(x > u) return 0;
if(y > v) return 0;
return pre[u][v] - pre[x - 1][v] - pre[u][y - 1] + pre[x - 1][y - 1];
}
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se;
for (int i = 1; i <= n; i++) cin >> w[i];
for(int i = 1; i <= n; i++) {
open[a[i].fi]++;
close[a[i].se + 1]++;
}
memset(dp, -0x3f, sizeof(dp));
ll temp = dp[0][0][0];
dp[0][0][0] = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j <= n; j++)
for(int k = 0; k <= n; k++) if(dp[i][j][k] != temp) {
// cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << endl;
int newj = j + open[i + 1];
int newk = k - close[i + 1];
// if(i == 2 && j == 0 && k == 3) cout << newj << ' ' << newk << endl;
if(newk < 0) continue;
for(int x = 0; x * (i + 1) <= newj; x++) {
maximize(dp[i + 1][newj - x * (i + 1)][newk + x * (i + 1)], dp[i][j][k] + w[i + 1] * x);
}
}
ll res = temp;
for(int i = 0; i <= n; i++) maximize(res, dp[n][0][i]);
if(res == temp) cout << "impossible";
else cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(TASK".inp" , "r" , stdin);
// freopen(TASK".out" , "w" , stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11892kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2ms
memory: 13328kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: 0
Accepted
time: 2ms
memory: 11768kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 2ms
memory: 14172kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: 0
Accepted
time: 0ms
memory: 12352kb
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:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 2ms
memory: 11964kb
input:
14 3 3 1 2 2 3 2 3 2 3 1 1 2 3 1 3 3 3 1 3 1 3 1 2 2 3 1 3 -9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573
output:
-16558567
result:
ok single line: '-16558567'
Test #7:
score: 0
Accepted
time: 0ms
memory: 12712kb
input:
14 1 2 1 4 2 3 3 5 4 5 2 5 2 4 2 4 1 2 3 4 1 5 2 4 1 1 4 5 -13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167
output:
-2673021
result:
ok single line: '-2673021'
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 11728kb
input:
14 2 3 4 4 1 7 3 6 3 4 1 1 1 4 4 7 3 7 1 7 2 3 6 6 1 1 3 6 2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961
output:
10814681
result:
wrong answer 1st lines differ - expected: '5939733', found: '10814681'