Submission #532084

#TimeUsernameProblemLanguageResultExecution timeMemory
532084fhvirusNaan (JOI19_naan)C++17
5 / 100
1 ms332 KiB
// Knapsack DP is harder than FFT. #include <bits/stdc++.h> using namespace std; typedef int64_t ll; typedef pair<int, int> pii; #define pb emplace_back #define AI(x) begin(x),end(x) #define ff first #define ss second #ifdef OWO #define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args) template <class I> void LKJ(I&&x) { cerr << x << endl; } template <class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); } template <class I> void OI(I a, I b) { while (a != b) cerr << *a << " \n"[(a = next(a)) == b]; } #else #define debug(...) 0 #define OI(...) 0 #endif const int kN = 2002; const int kC = 100000; int N, L, V[kN][kN]; ll ori[kN]; bool solve(const vector<int>& perm) { int k = 0; ll sum = 0; while (k < L and (sum + V[perm[0]][k + 1]) * N < ori[perm[0]]) { sum += V[perm[0]][k + 1]; ++k; } ll la = ori[perm[0]] - sum * N; ll lb = N * V[perm[0]][k + 1]; ll left = 0; for (int i = 1; i <= L; ++i) left += V[perm[1]][i]; left = (left - sum) * lb - V[perm[1]][k + 1] * la; if (left * N < ori[perm[1]]) return false; cout << k * lb + la << ' ' << lb << '\n'; for (const int& i: perm) cout << i << " \n"[i == perm.back()]; return true; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> L; for (int i = 1; i <= N; ++i) for (int j = 1; j <= L; ++j) { cin >> V[i][j]; ori[i] += V[i][j]; } vector<int> perm(N); iota(AI(perm), 1); do if (solve(perm)) exit(0); while (next_permutation(AI(perm))); assert(0); cout << -1 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...