QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569117 | #7185. Poor Students | masttf | WA | 2ms | 4040kb | C++20 | 2.6kb | 2024-09-16 20:39:17 | 2024-09-16 20:39:17 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout<<endl<<endl;
}
template<class T, class... Ts>
void err(T arg, Ts ... args) {
cout<<fixed<<setprecision(10)<<arg<< ' ';
err(args...);
}
constexpr int maxn = 11, Max = 1e15;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q[maxn][maxn];
void solve(){
int n, k; cin >> n >> k;
vector cost(n + 1, vector<int> (k + 1));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
cin >> cost[i][j];
}
}
vector<int> a(k + 1);
for(int i = 1; i <= k; i++) cin >> a[i];
int ans = 0;
vector<int>bl(n + k + 1);
for(int i = 1; i <= k; i++){
bl[i + n] = i;
}
for(int i = 0; i <= k; i++){
for(int j = 1; j <= k; j++){
if(i == 0)q[i][j].push({Max, 0});
else q[i][j].push({Max, i + n});
}
}
auto add = [&](int x, int s, int val) -> void{
for(int i = 1; i <= k; i++){
if(i == s)continue;
q[s][i].push({cost[x][i] - val, x});
}
};
for(int i = 1; i <= n; i++){
add(i, 0, 0);
}
int tot = n;
while(tot--){
int mx = Max;
pair<int, int> op = {0, 0};
for(int i = 0; i <= k; i++){
for(int j = 1; j <= k; j++){
while(bl[q[i][j].top().second] != i)q[i][j].pop();
}
}
for(int i = 0; i <= k; i++){
for(int j = 1; j <= k; j++){
if(a[j]){
if(i == 0){
if(q[i][j].top().first < mx){
mx = q[i][j].top().first;
op = {i, j};
}
}else{
int val = q[0][i].top().first + q[i][j].top().first;
if(val < mx){
mx = val;
op = {i, j};
}
}
}
}
}
ans += mx;
auto [u, v] = op;
a[v]--;
if(v == 0){
cout << "No" << endl;
break;
}
if(u == 0){
int x = q[u][v].top().second;
q[u][v].pop();
bl[x] = v;
add(x, v, cost[x][v]);
}else{
int x = q[0][u].top().second;
int y = q[u][v].top().second;
q[0][u].pop();
q[u][v].pop();
bl[x] = u;
add(x, u, cost[x][u]);
bl[y] = v;
add(y, v, cost[y][v]);
}
}
// for(int i = 1; i <= n; i++){
// dbg(i, bl[i]);
// }
cout << ans << '\n';
return ;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
6 2 1 2 1 3 1 4 1 5 1 6 1 7 3 4
output:
12
result:
ok answer is '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 3 1 2 3 2 4 6 6 5 4 1 1 1
output:
8
result:
ok answer is '8'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 4040kb
input:
1000 10 734 303 991 681 755 155 300 483 702 442 237 256 299 675 671 757 112 853 759 233 979 340 288 377 718 199 935 666 576 842 537 363 592 349 494 961 864 727 84 813 340 78 600 492 118 421 478 925 552 617 517 589 716 7 928 638 258 297 706 787 266 746 913 978 436 859 701 951 137 44 815 336 471 720 2...
output:
92190
result:
wrong answer expected '92039', found '92190'