제출 #477505

#제출 시각아이디문제언어결과실행 시간메모리
477505kaxzertKnapsack (NOI18_knapsack)C++17
100 / 100
60 ms5004 KiB
/** 00 00 11 00 00 111111 00000 111111 000000 00 00 1111 0000 11 00 11 11 000000 0000 11 11 00 11 00000 111111 00 00 00 11111111 0000 11 00 11 11 00 00 00 11 11 00 00 111111 00000 11 11 00 **/ #include<bits/stdc++.h> using namespace std; void setIO(string s) { freopen((s+".inp").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } void setIOusaco(string s) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #define fto(i, a, b) for(int i = a; i <= b; ++i) #define fdto(i, a, b) for(int i = a; i >= b; --i) #define bugarr(a, i, j) cout << #a << "{" << i << "..." << j << "}:"; fto(k, i, j-1) cout << a[k] << ", "; cout << a[j] << endl; #define ll long long #define db double #define ldb long double #define ii pair<int, int> #define ff first #define ss second #define pb push_back #define mp make_pair #define eb emplace_back #define vt vector #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define trav(i, a) for(auto &i : a) #define sz(a) (int)a.size() #define fast ios::sync_with_stdio(false); cin.tie(0) template<typename T, typename V> bool ckmin(T &a, V b) {return (b < a)? a = b, true : false;} template<typename T, typename V> bool ckmax(T &a, V b) {return (b > a)? a = b, true : false;} void print(int x) {cout << x;} void print(long long x) {cout << x;} void print(unsigned x) {cout << x;} void print(unsigned long long x) {cout << x;} void print(double x) {cout << fixed << x;} void print(long double x) {cout << fixed << x;} void print(char x) {cout << "'" << x << "'";} void print(string x) {cout << '"' << x << '"';} void print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void print(const pair<T, V> &x) {cout << '{'; print(x.ff); cout << ", "; print(x.ss); cout << '}';} template<typename T> void print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? ", " : ""), print(i); cout << "}";} void _print() {cout << "]" << endl;} template <typename T, typename... V> void _print(T t, V... v) {print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifdef TAP #define bug(x...) cout << "[" << #x << "] = ["; _print(x) #else #define bug(x...) #endif int main() { fast; int s, n; cin >> s >> n; vt<vt<pair<ll, ll> > > m(s+1); vt<vt<ll> > temp(s+1); fto(i, 1, n) { int v, w, k; cin >> v >> w >> k; m[w].eb(mp(v, k)); } vt<int> sth; fto(i, 1, s) { if (m[i].empty()) continue; sth.pb(i); sort(all(m[i]), [](pair<ll, ll> a, pair<ll, ll> b)->bool { return a.ff < b.ff; }); int need = s/i; while(!m[i].empty() && need > 0) { temp[i].pb(m[i][sz(m[i])-1].ff); if (sz(temp[i]) > 1) temp[i][sz(temp[i])-1] += temp[i][sz(temp[i])-2]; if ((m[i][sz(m[i])-1].ss -= 1) == 0) { m[i].pop_back(); } --need; } } vt<vt<ll> > f(2, vt<ll>(s+2, 0)); fto(i, 0, sz(sth)-1) { int li = i&1; int w = sth[i]; fto(j, 1, s) f[li][j] = f[li^1][j]; //bug(w); //bug(temp[w]); fto(j, 0, sz(temp[w])-1) { fto(k, w*(j+1), s) { f[li][k] = max(f[li][k], f[li^1][k-w*(j+1)] + temp[w][j]); } } //bug(f[li]); } ll ans = 0; fto(i, 1, s) { ans = max(ans, f[(sz(sth)-1)&1][i]); } cout << ans << '\n'; return 0; }

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

knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen((s+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'void setIOusaco(std::string)':
knapsack.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s+".out").c_str(),"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...