QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65655 | #2481. Pickpockets | UBB_Zalau00# | WA | 2ms | 3684kb | C++14 | 2.4kb | 2022-12-02 19:26:32 | 2022-12-02 19:26:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct team_t{
int duration;
int profit;
};
struct dp_state_t{
int segment;
int space_taken;
dp_state_t(){
segment = 0;
space_taken = 0;
}
bool operator < (const dp_state_t &other)const{
if(this->segment != other.segment){
return this->segment < other.segment;
}
return this->space_taken < other.space_taken;
}
};
int main(){
int h, t;
scanf("%d %d", &h, &t);
vector<int> heights(h + 1, 0);
for(int i = 1;i <= h;i++){
scanf("%d", &heights[i]);
heights[i] = min(heights[i], t);
}
vector<team_t> teams(t);
for(auto &it:teams){
cin >> it.duration;
cin >> it.profit;
}
vector<int> lengths;
for(int i = 1;i <= t;i++){
int current_length = 0;
for(int j = 1;j <= h;j++){
if(heights[j] < i){
if(current_length > 0){
lengths.push_back(current_length);
}
current_length = 0;
} else {
current_length++;
}
}
if(current_length > 0){
lengths.push_back(current_length);
}
}
sort(lengths.begin(), lengths.end());
vector<dp_state_t> dp(1 << t);
for(int conf = 1;conf < (1 << t);conf++){
dp[conf].segment = (int)lengths.size() + 1;
dp[conf].space_taken = 0;
}
for(int conf = 0;conf < (1 << t);conf++){
if(dp[conf].segment >= (int)lengths.size()){
continue;
}
for(int i = 0;i < t;i++){
if((conf >> i) & 1){
continue;
}
dp_state_t nxt = dp[conf];
if(nxt.space_taken + teams[i].duration <= lengths[nxt.segment]){
nxt.space_taken += teams[i].duration;
}else{
int next_segment = lower_bound(lengths.begin() + nxt.segment + 1, lengths.end(), teams[i].duration) - lengths.begin();
nxt.segment = next_segment;
nxt.space_taken = teams[i].duration;
}
if(nxt < dp[conf | (1 << i)]){
dp[conf | (1 << i)] = nxt;
}
}
}
int answer = 0;
for(int conf = 0;conf < (1 << t);conf++){
if(dp[conf].segment >= (int)lengths.size()){
continue;
}
int local_answer = 0;
for(int i = 0;i < t;i++){
if((conf >> i) & 1){
local_answer += teams[i].profit;
}
}
answer = max(answer, local_answer);
}
printf("%d\n", answer);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
3 4 2 1 2 3 2 1 1 1 2 1 3
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
1 5 2 1 2 1 5 1 3 1 5 1 3
output:
10
result:
ok single line: '10'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
1 5 1 1 2 1 1 1 2 1 5 1 2
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3564kb
input:
1 7 0 1 5 1 5 1 5 1 2 1 5 1 3 1 6
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 3684kb
input:
3 6 2 1 1 2 1 3 5 2 3 3 3 2 4 3 3
output:
5
result:
wrong answer 1st lines differ - expected: '0', found: '5'