답안 #532086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532086 2022-03-02T05:24:00 Z fhvirus Naan (JOI19_naan) C++17
24 / 100
3749 ms 492 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 solve(const vector<int>& perm) {
    	vector<ll> x(1, 0);
    	for (const int& i: perm) {
    		int j = x.back();
    		while (j <= dupl * L and (f(i, j) - f(i, x.back())) * N < ori[i] * dupl)
    			++j;
    		if (j > dupl * L) return false;
    		x.pb(j);
    	}
     
    	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 = max(dupl, (ll) V[i][j]);
    		}
     
    	dupl = dupl * N;
     
     
    	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;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3749 ms 356 KB Output is correct
3 Correct 2134 ms 356 KB Output is correct
4 Correct 2407 ms 376 KB Output is correct
5 Correct 2615 ms 348 KB Output is correct
6 Correct 445 ms 332 KB Output is correct
7 Correct 1858 ms 348 KB Output is correct
8 Correct 876 ms 364 KB Output is correct
9 Correct 293 ms 332 KB Output is correct
10 Correct 542 ms 356 KB Output is correct
11 Runtime error 1799 ms 484 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 12 ms 492 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 3 ms 484 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 2 ms 412 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 2 ms 456 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 3 ms 452 KB Output is correct
23 Correct 0 ms 320 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3749 ms 356 KB Output is correct
3 Correct 2134 ms 356 KB Output is correct
4 Correct 2407 ms 376 KB Output is correct
5 Correct 2615 ms 348 KB Output is correct
6 Correct 445 ms 332 KB Output is correct
7 Correct 1858 ms 348 KB Output is correct
8 Correct 876 ms 364 KB Output is correct
9 Correct 293 ms 332 KB Output is correct
10 Correct 542 ms 356 KB Output is correct
11 Runtime error 1799 ms 484 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -