# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103845 | FernandoJC07 | Knapsack (NOI18_knapsack) | C++14 | Compilation error | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <math.h>#include <string>#include <sstream>#include <algorithm>#include <vector>#include <utility>#include <stdio.h>#include <unordered_map>#include <cstring>#define Kaspárov mainusing namespace std;#pragma GCC optimize("Ofast,unroll-loops")
#define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/
Compilation message (stderr)
knapsack.cpp:2:18: warning: extra tokens at end of #include directive 2 | #include <math.h>#include <string>#include <sstream>#include <algorithm>#include <vector>#include <utility>#include <stdio.h>#include <unordered_map>#include <cstring>#define Kaspárov mainusing namespace std;#pragma GCC optimize("Ofast,unroll-loops") | ^ knapsack.cpp:3:772: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:797: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:814: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:846: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:861: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:891: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:894: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ | ^ knapsack.cpp:3:897: error: extended character is not valid in an identifier 3 | #define int long long#define ull unsigned long long#define ios ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(0); #define pb push_back#define ff first#define ss second#define pb push_back#define all(x) (x).begin(), (x).end()#define lb lower_bound#define ordenar(x) sort( x.begin(), x.end() )#define ordenarA(x,n) sort( x, x + n )#define sf(n) scanf("%d", &n)#define sff(n,m) scanf("%d%d",&n,&m)#define sfl(n) scanf("%lld", &n)#define sffl(n,m) scanf("%lld%lld",&n,&m)#define pf(n) printf("%d\n",n)#define pfl(n) printf("%lld ",n)#define pfs(s) printf("%s\n",s)const int MAXN = 1e6+5, mod = 1e9+7;void solve();int32_t main(){ ios; int t = 1; while(t--){ solve(); } fflush(stdin); fflush(stdout);}void solve(){ int s, n; cin>>s>>n; int dp[s+1]; memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i<n; ++i){ int a, b, c; cin>>a>>b>>c; int pm[s+1]; for(int j = 0; j<=s; ++j) pm[j] = dp[j]; for(int j = 0; j<=s; ++j){ if(dp[j] != -1){ int lugar = j; int suma = 0; int klk = c; while(klk--){ lugar += b; suma += a; if(lugar>s) break; pm[lugar] = max(dp[j] + suma, dp[lugar]); } } } for(int j = 0; j<=s; ++j) dp[j] = pm[j]; } int maxn = -1; for(int x: dp) maxn = max(maxn, x); cout<<maxn;}/*15 54 12 12 1 110 4 11 1 12 2 1*/ |