제출 #437458

#제출 시각아이디문제언어결과실행 시간메모리
437458KazamaHoangKnapsack (NOI18_knapsack)C++11
73 / 100
40 ms3820 KiB
/* -> Written by <- ----------- |K_A_Z_A_M_A| |___________| | ___ | | (^_^) | | /( | )\ | |____|_|____| H O A N G */ //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; using ll = long long; using db = long double; //using int = long long #define Task "cowjog" #define F first #define S second #define eb emplace_back #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() #define bit(x, i) (((x) >> (i)) & 1) #define endl '\n' #define fr(i,a,b) for (int i = (int)(a); i <= (int)(b); ++ i) #define FR(i,a,b) for (int i = (int)(a); i < (int)(b); ++ i) #define frr(i,a,b) for (int i = (int)(a); i >= (int)(b); -- i) #define fre(i, a) for (auto &i : a) #define debug(x) cerr << #x << " is " << x << "\n"; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> const int MOD = 1e9 + 7; const ll MM = (ll)MOD * MOD; const int base = 331; const int B = 32; const int inf = 1e9 + 7; const ll INF = 1e18 + 7; const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; const int dy8[] = {1, -1, 0, 1, -1, 0, 1, -1}; const int dx4[] = {0, 0, 1, -1}; const int dy4[] = {1, -1, 0, 0}; int s, n; vector <pair <int, int>> e[2005]; pair <int, int> a[22000]; ll dp[2005]; void solve(int test_case) { cin >> s >> n; fr(i, 1, n) { int v, w, k; cin >> v >> w >> k; e[w].eb(v, k); } n = 0; fr(w, 1, s) { sort(all(e[w]), greater <pair <int, int>> ()); int bef = n; fre(p, e[w]) { fr(j, 1, p.S) { a[++n] = {w, p.F}; if ((n - bef) * w >= s) break; } } } fr(i, 1, s) dp[i] = - INF; fr(i, 1, n) { frr(j, s, 0) if (j + a[i].F <= s) dp[j+a[i].F] = max(dp[j+a[i].F], dp[j] + a[i].S); } ll res = - INF; fr(i, 0, s) res = max(res, dp[i]); cout << res; } signed main(){ cin.tie(0)->sync_with_stdio(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); freopen(".ou", "w", stderr); } else if (fopen(Task".in", "r")) { freopen(Task".in", "r", stdin); freopen(Task".out", "w", stdout); } int test_case = 1; // cin >> test_case; // prepare(); for (int i = 1; i <= test_case; ++ i) { solve(i); // bf(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(".ou", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(Task".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...