Submission #1112333

# Submission time Handle Problem Language Result Execution time Memory
1112333 2024-11-14T05:11:48 Z whyalwaysmezzz Knapsack (NOI18_knapsack) C++14
73 / 100
211 ms 262144 KB
//Nếu thế giới có 8 tỷ người yêu em, anh là một trong số họ
//Nếu thế giới có 1 người yêu em, thì anh chính là người đó
//Nếu thế giới không còn ai yêu em, thì có nghĩa là anh đã chết </3
//dyk19b1
#include <bits/stdc++.h>
// #define int long long
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define BIT(mask,i) ((mask >> i) & 1ll )
#define endl '\n'  
#define all(x) x.begin(),x.end()
#define ii pair <int,int> 
using namespace std;
#define read doc() 
// int doc () {bool minus = false;int result = 0;char ch;ch = getchar();while (true) {if (ch == '-') break;if (ch >= '0' && ch <= '9') break;ch = getchar();}if (ch == '-') minus = true; else result = ch-'0';while (true) {ch = getchar();if (ch < '0' || ch > '9') break;result = result*10 + (ch - '0');}if (minus)return -result;else return result;}
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// template <class T> T rand(T l, T h) { return uniform_int_distribution <T> (l, h) (rng); } 
// template <class T> T rand(T h) { return uniform_int_distribution <T> (0, h - 1) (rng); }
// template<class X, class Y>bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;}
// template<class X, class Y>bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;}
// const long long oo = 1e18;
// const int N = 1e6+5;
// const int MOD = 1e9+7;
int s,n; 
struct typ
{
	long long v,w,k;
} a[100005];
vector <pair <long long,long long> > b;
// int dp[50010][2001];
vector < vector <long long > > dp;
long long solve(int i,int j)
{
	if (i > n) return 0;
	if (j == s) return 0;
	if (~dp[i][j]) return dp[i][j];
	long long cur = 0;
	if (j + b[i].se <= s) cur = max(cur,1ll * solve(i+1,j+b[i].se)+b[i].fi);
	cur = max(cur,solve(i+1,j)); 
	return dp[i][j] = cur;
}
void TnKh()
{
	cin >> s >> n;
	FOR(i,1,n)
	{
		long long v,w,k;
		cin >> v >> w >> k;
		a[i] = {v,w,k};
	}
	FOR(i,1,n)
	{
		auto [v,w,k] = a[i];
		int j = 0;
		for(;(1ll << (j+1))-1 <= k;j++)
		{
			long long kc = (1ll << j);
			if (w * kc > s) break;
			b.push_back(make_pair(v*kc,w*kc));
			// weight[w *kc] = max(weight[kc*w],v*kc);
		}
		if (k-(1 << (j))+1) b.push_back(make_pair(v*(k-(1ll << (j))+1),w * (k-(1ll << (j))+1) ));
		// cout << (k-(1 << (j))+1);
	}
	dp.assign((int)b.size(),vector <long long> (s+1,-1));
		n = b.size()-1;
		// cout << b[6].fi << " " << b[6].se;
	cout << solve(0,0);
    return;
}
#define TASK "task"
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //  freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);
    int Dyk19b1 = 1;
    // cin >> Dyk19b1;
    while (Dyk19b1--) TnKh();
    return 0;       
}





Compilation message

knapsack.cpp: In function 'void TnKh()':
knapsack.cpp:55:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |   auto [v,w,k] = a[i];
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 3 ms 1872 KB Output is correct
7 Correct 3 ms 2044 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 3 ms 1872 KB Output is correct
10 Correct 3 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 3 ms 1872 KB Output is correct
7 Correct 3 ms 2044 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 3 ms 1872 KB Output is correct
10 Correct 3 ms 1884 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 6480 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 2104 KB Output is correct
15 Correct 3 ms 3408 KB Output is correct
16 Correct 6 ms 3920 KB Output is correct
17 Correct 3 ms 2040 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 8 ms 2640 KB Output is correct
20 Correct 4 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 3 ms 1872 KB Output is correct
11 Correct 3 ms 2044 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 3 ms 1872 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 6 ms 6480 KB Output is correct
17 Correct 2 ms 1872 KB Output is correct
18 Correct 2 ms 2104 KB Output is correct
19 Correct 3 ms 3408 KB Output is correct
20 Correct 6 ms 3920 KB Output is correct
21 Correct 3 ms 2040 KB Output is correct
22 Correct 4 ms 2640 KB Output is correct
23 Correct 8 ms 2640 KB Output is correct
24 Correct 4 ms 2640 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 46 ms 15964 KB Output is correct
27 Correct 2 ms 1872 KB Output is correct
28 Correct 3 ms 1872 KB Output is correct
29 Correct 4 ms 3408 KB Output is correct
30 Correct 8 ms 5200 KB Output is correct
31 Correct 3 ms 2044 KB Output is correct
32 Correct 4 ms 2724 KB Output is correct
33 Correct 6 ms 2384 KB Output is correct
34 Correct 4 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 3 ms 1872 KB Output is correct
11 Correct 3 ms 2044 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 3 ms 1872 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 6 ms 6480 KB Output is correct
17 Correct 2 ms 1872 KB Output is correct
18 Correct 2 ms 2104 KB Output is correct
19 Correct 3 ms 3408 KB Output is correct
20 Correct 6 ms 3920 KB Output is correct
21 Correct 3 ms 2040 KB Output is correct
22 Correct 4 ms 2640 KB Output is correct
23 Correct 8 ms 2640 KB Output is correct
24 Correct 4 ms 2640 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 46 ms 15964 KB Output is correct
27 Correct 2 ms 1872 KB Output is correct
28 Correct 3 ms 1872 KB Output is correct
29 Correct 4 ms 3408 KB Output is correct
30 Correct 8 ms 5200 KB Output is correct
31 Correct 3 ms 2044 KB Output is correct
32 Correct 4 ms 2724 KB Output is correct
33 Correct 6 ms 2384 KB Output is correct
34 Correct 4 ms 2660 KB Output is correct
35 Correct 27 ms 16584 KB Output is correct
36 Runtime error 211 ms 262144 KB Execution killed with signal 9
37 Halted 0 ms 0 KB -