# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
532060 |
2022-03-02T04:52:55 Z |
fhvirus |
Naan (JOI19_naan) |
C++17 |
|
0 ms |
332 KB |
// 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;
int N, L, V[kN][kN];
ll dupl, pre[kN][kN], ori[kN];
ll f(int i, ll j) {
int k = j / dupl;
return pre[i][k] * dupl + V[i][k + 1] * (j - k * dupl);
}
bool cmp(int i, ll l, ll r) {
debug(i, l, r, f(i, l), f(i, r));
// f(i, l, r) / dupl >= ori[i] / N
return (f(i, r) - f(i, l)) * N >= ori[i] * dupl;
}
bool solve(const vector<int>& perm) {
vector<ll> x(1, 0);
for (const int& i: perm) {
ll j = x.back();
if (!cmp(i, x.back(), L * dupl)) return false;
for (ll lg = (1ll << 60); lg > 0; lg >>= 1)
if (j + lg <= L * dupl and !cmp(i, x.back(), j + lg))
j += lg;
x.pb(j + 1);
debug(i, j + 1);
}
x.back() = dupl * L;
for (int i = 1; i < N; ++i)
cout << x[i] << ' ' << dupl << '\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];
pre[i][j] = pre[i][j - 1] + V[i][j];
ori[i] += V[i][j];
}
dupl = 500'000 * N;
vector<int> perm(N);
iota(AI(perm), 1);
do if (solve(perm)) exit(0);
while (0 and next_permutation(AI(perm)));
cout << -1 << '\n';
return 0;
}
Compilation message
naan.cpp: In function 'bool cmp(int, ll, ll)':
naan.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
naan.cpp:29:2: note: in expansion of macro 'debug'
29 | debug(i, l, r, f(i, l), f(i, r));
| ^~~~~
naan.cpp: In function 'bool solve(const std::vector<int>&)':
naan.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
naan.cpp:43:3: note: in expansion of macro 'debug'
43 | debug(i, j + 1);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
328 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |