이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 502;
int n, k, c;
int a[mxn][6];
bool vis[5000][mxn];
vector<int> v;
int ans(int p){
v.clear();
int cnt = 0;
fr(i, 0, n){
if(vis[p][i]) continue;
++cnt;
}
if(cnt < k) return -i_inf;
int res = 0;
fr(j, 0, k){
int best = -1, mx = -1;
fr(i, 0, n){
if(vis[p][i] || find(all(v), i) != v.end()) continue;
if(a[i][j] > mx){
mx = a[i][j];
best = i;
}
}
v.pb(best);
}
fr(i, 0, k){
int mx = 0;
for(auto u : v) mx = max(mx, a[u][i]);
res += mx;
}
return res;
}
bool done[1000000];
int search(){
int pos = 0;
int ret = 0;
int processed = 0;
while(processed < c){
int best = -1, mx = -i_inf;
fr(i, 0, pos+1){
if(done[i]) continue;
int temp_ans = ans(i);
if(temp_ans > mx){
mx = temp_ans;
best = i;
}
}
done[best] = true;
ret = ans(best);
++processed;
for(auto u : v){
++pos;
fr(i, 0, n) vis[pos][i] = vis[best][i];
vis[pos][u] = true;
}
}
return ret;
}
void solve(){
cin >> n >> k >> c;
fr(i, 0, n){
fr(j, 0, k){
cin >> a[i][j];
}
}
cout<<search()<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |