QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569236#7185. Poor StudentsmasttfWA 2ms4096kbC++202.4kb2024-09-16 21:26:182024-09-16 21:26:18

Judging History

你现在查看的是最新测评结果

  • [2024-09-16 21:26:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4096kb
  • [2024-09-16 21:26:18]
  • 提交

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 = 1e18;
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) -> void{
    	int s = bl[x];
    	for(int i = 1; i <= k; i++){
    		if(i == s)continue;
    		q[s][i].push({cost[x][i] - cost[x][s], x});
    	}
    };
    for(int i = 1; i <= n; i++)add(i);
    int tot = n;
    while(tot--){
    	int mx = 2e9;
    	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] == 0)continue;
    			int val = q[i][j].top().first;
				if(i != 0) val += q[0][i].top().first;
				if(val < mx){
					mx = val;
					op = {i, j};
				}
    		}
    	}
    	ans += mx;
    	auto [u, v] = op;
    	a[v]--;
    	assert(v != 0);
    	//dbg(u, v);
    	if(u == 0){
    		int x = q[u][v].top().second;
    		q[u][v].pop();
    		bl[x] = v;
    		add(x);
    	}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;
    		bl[y] = v;
    		add(x);
    		add(y);
    	}
    }
    // 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: 3552kb

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

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

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'