#include <bits/stdc++.h>
using namespace std;
int n,k,c;
int a[505][7];
struct config
{
int val[7],sumval;
vector<int> alesi;
void baga(int x)
{
alesi.push_back(x);
sort(alesi.begin(),alesi.end());
sumval=0;
for(int i=1;i<=k;i++)
{
val[i] = max(val[i], a[x][i]);
sumval += val[i];
}
}
void schimba(int poz, int newv)
{
alesi[poz] = newv;
for(int i=poz-1;i>=0;i--)
if(alesi[i] > alesi[i+1])
swap(alesi[i], alesi[i+1]);
for(int i=poz+1;i<k;i++)
if(alesi[i] < alesi[i-1])
swap(alesi[i], alesi[i-1]);
sumval=0;
for(int i=1;i<=k;i++)
{
val[i]=0;
for(int j:alesi)
val[i] = max(val[i], a[j][i]);
sumval += val[i];
}
}
bool is_ales(int x)
{
for(int i:alesi)
if(i==x)
return 1;
return 0;
}
};
bool operator<(config x, config y)
{
if(x.sumval < y.sumval)
return 1;
if(x.sumval > y.sumval)
return 0;
return x.alesi < y.alesi;
}
bool ales[505];
config init;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k>>c;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
cin>>a[i][j];
}
}
assert(k<=n);
for(int i=1;i<=k;i++)
{
int mxm=-1,unde=-1;
for(int j=1;j<=n;j++)
{
if(!ales[j] && a[j][i]>mxm)
{
mxm = a[j][i];
unde = j;
}
}
assert(unde!=-1);
ales[unde] = 1;
init.baga(unde);
}
priority_queue<config> pq;
map<config,int> inq;
pq.push(init);
inq[init]=1;
int cnt=0;
while(!pq.empty())
{
config aux = pq.top();
pq.pop();
cnt++;
if(cnt==c)
{
cout<<aux.sumval;
return 0;
}
for(int s=0;s<k;s++)
{
int vechi = aux.alesi[s];
for(int i=1;i<=n;i++)
{
if(!aux.is_ales(i))
{
config newc = aux;
newc.schimba(s,i);
if(!inq[newc])
{
pq.push(newc);
inq[newc]=1;
}
}
}
}
}
assert(0==1);
return 0;
}
/*
5 4 4
7 0 4 9
3 0 8 4
1 1 3 7
5 1 3 4
4 2 2 9
*/
Compilation message
olympiads.cpp: In function 'int main()':
olympiads.cpp:100:17: warning: unused variable 'vechi' [-Wunused-variable]
100 | int vechi = aux.alesi[s];
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1890 ms |
28676 KB |
Output is correct |
2 |
Correct |
1621 ms |
28476 KB |
Output is correct |
3 |
Correct |
1619 ms |
28680 KB |
Output is correct |
4 |
Correct |
1348 ms |
7080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
465 ms |
22308 KB |
Output is correct |
2 |
Correct |
450 ms |
19976 KB |
Output is correct |
3 |
Correct |
431 ms |
21364 KB |
Output is correct |
4 |
Correct |
412 ms |
19912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2060 ms |
150200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1890 ms |
28676 KB |
Output is correct |
2 |
Correct |
1621 ms |
28476 KB |
Output is correct |
3 |
Correct |
1619 ms |
28680 KB |
Output is correct |
4 |
Correct |
1348 ms |
7080 KB |
Output is correct |
5 |
Correct |
465 ms |
22308 KB |
Output is correct |
6 |
Correct |
450 ms |
19976 KB |
Output is correct |
7 |
Correct |
431 ms |
21364 KB |
Output is correct |
8 |
Correct |
412 ms |
19912 KB |
Output is correct |
9 |
Execution timed out |
2060 ms |
150200 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |