Submission #205743

#TimeUsernameProblemLanguageResultExecution timeMemory
205743ics0503Olympiads (BOI19_olympiads)C++17
100 / 100
13 ms1428 KiB
#include<stdio.h> #include<vector> #include<algorithm> #include<queue> #include<set> using namespace std; long long C[515][7]; struct xy { int x, y; }; vector<xy>L[6]; bool sort_x(xy a, xy b) { if (a.x != b.x)return a.x > b.x; return a.y < b.y; } struct state { int v, a[6]; bool operator <(const state p)const { return v < p.v; } }; int n, k, c; long long trans(int a[]) { long long res = 0; for (long long i = 0, j = 1; i < k; i++, j *= (n+1)) { res += j * a[i]; } return res; } set<long long>ck; set<long long>alreadyDone; int cck[515], S[6], V[6], G[6], pnum; int dfs(int dep) { if (dep == k - pnum) { long long g = 0; for (int i = 0; i < pnum; i++)V[i] = S[i]; for (int i = pnum; i < k; i++)V[i] = G[i - pnum]; sort(V, V + k); for (long long i = 0, j = 1; i < k; i++, j *= (n + 1)) g += V[i] * j; int ret = alreadyDone.find(g) == alreadyDone.end(); alreadyDone.insert(g); return ret; } int ret = 0; for (int i = 1; i <= n; i++) { if (cck[i])continue; G[dep] = i; ret += dfs(dep + 1); } return ret; } int main() { int i, j, sum = 0; scanf("%d%d%d", &n, &k, &c); for (i = 1; i <= n; i++) { for (j = 0; j < k; j++) { int v; scanf("%d", &v); L[j].push_back({ v,i }); } } for (i = 0; i <= 500; i++) { C[i][0] = 1; for (j = 1; j <= 6 && j <= i; j++)C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } for (i = 0; i < k; i++)sort(L[i].begin(), L[i].end(), sort_x), sum+=L[i][0].x; priority_queue<state>H; H.push({ sum, {0,0,0,0,0,0} }); int cnt = 0; while (!H.empty()) { state now = H.top(); H.pop(); for (i = 0; i < k; i++) { int who = L[i][now.a[i]].y; S[i] = who; cck[who] = 1; } sort(S, S + k); pnum = unique(S, S + k) - S; for (i = 0; i < pnum; i++)V[i] = S[i]; int nowv = pnum; for (i = pnum; nowv < k && i <= n; i++) { if (cck[i] == 0)V[nowv++] = i; } sort(V, V + k); long long ret = 0; for (i = 0, j = 1; i < k; i++, j *= (n + 1)) ret += V[i] * j; if (alreadyDone.find(ret) == alreadyDone.end()) { if (c <= C[n - pnum][k - pnum]) { printf("%d", now.v); return 0; } ret = dfs(0); cnt += ret; if (c <= cnt) { printf("%d", now.v); return 0; } } for (int g : S)cck[g] = 0; for (i = 0; i < k; i++) if (now.a[i] + 1 < n) { state nxt = now; nxt.a[i]++; nxt.v = now.v - (L[i][now.a[i]].x - L[i][nxt.a[i]].x); long long transv = trans(nxt.a); if (ck.find(transv) == ck.end()) { ck.insert(transv); H.push(nxt); } } } return 0; }

Compilation message (stderr)

olympiads.cpp: In function 'int main()':
olympiads.cpp:53:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int i, j, sum = 0; scanf("%d%d%d", &n, &k, &c);
                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:56:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int v; scanf("%d", &v);
           ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...