// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
// template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const ll BIG = ll(7e15);
const int LG = 18;
const int nax = 505;
ll get() { return rand() * 1LL * rand() * 1LL * rand(); };
ll rnd() { return ((get() % MOD) * 1LL * (rand() % 17) + (get() % MOD)) % BIG; };
using B = bitset<nax>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, K, C; cin >> N >> K >> C;
V<vi> A(N, vi(K)); for(auto& v : A) {
for(auto& x : v) cin >> x;
}
vl H(N); for(auto& x : H) x = rnd();
map<ll, int> IDX; IDX[0] = 0; int cur = 1;
V<B> VIS;
V<vi> X;
vi S;
VIS.pb(B()); X.pb(vi(K, 0)); S.pb(0);
set<pl> T; T.insert(mp(0, 0));
set<int> CUR;
auto get = [&](ll h) {
if (sz(CUR) == 0) {
CUR.insert(cur++);
while(sz(VIS) < cur) VIS.emplace_back();
while(sz(X) < cur) X.emplace_back();
while(sz(S) < cur) S.emplace_back();
}
if (IDX.find(h) == IDX.end()) {
IDX[h] = *begin(CUR);
CUR.erase(begin(CUR));
}
return IDX[h];
};
for(int t = 0; t < K; t++) {
set<pl> NT;
for(auto& r : T) {
int id = get(r.s);
for(int i = 0; i < N; i++) if (!VIS[id][i]) {
ll h = r.s ^ H[i];
int nid = get(h);
B vis = VIS[id]; vis[i] = 1;
vi x = X[id]; for(int k = 0; k < K; k++) x[i] = max(x[i], A[i][k]);
int s = accumulate(begin(x), end(x), 0);
// assert(nid < sz(VIS));
VIS[nid] = vis; X[nid] = x; S[nid] = s;
NT.insert(mp(s, h));
while (sz(NT) > C) {
ll hsh = (*begin(NT)).s; NT.erase(begin(NT));
int ID = get(hsh); IDX.erase(hsh);
CUR.insert(ID);
}
}
}
T.swap(NT);
}
// for(auto& x : T) cout << x.f << nl;
// while(sz(T) > C) T.erase(begin(T));
cout << (*begin(T)).f << nl;
exit(0-0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |