Submission #3429572
Source Code Expand
#include <iostream> #include <cassert> #include <climits> #include <bitset> #include <stack> #include <queue> #include <iomanip> #include <limits> #include <string> #include <cmath> #include <set> #include <map> #include <math.h> #include <algorithm> #include <vector> #include <string.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; long long int INF = 1e18; double Pi = 3.1415926535897932384626; long long int mod = 1000000007; vector<ll> G[500005]; vector<P> tree[500010]; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll,vector<ll>,greater<ll> > pqls; priority_queue <P,vector<P>,greater<P> > pqps; //small priority queue //top pop int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,-1,1}; char dir[] = "RULD"; //↓,→,↑,← #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(15)<<x<<endl; #define pu(x) cout<<x; #define re(i,a,b) for(i=a;i<=b;i++); #define pb push_back #define lb lower_bound #define ub upper_bound #define deba(x) cout<< #x << " = " << x <<endl ll rui(ll abc,ll bed){ //abcのbed乗を計算する if(bed==0){return 1;} else{ ll ced = rui(abc,bed/2); ced *= ced; ced %= mod; if(bed%2==1){ced*=abc; ced%=mod;} return ced; } } ll gcd(ll number1,ll number2){ if(number1 > number2){ swap(number1,number2); } if(number1 == 0 || number1 == number2){ return number2; }else{ return gcd(number2 % number1,number1); } } ll i,j,k,ii,jj; ll n,m,num,ans; ll a,b,c,d,e,g,h,r,bag; ll wn1,wn2,wn3,wn4; ll w[5005],v[5005]; ll dp[5][5005]; ll index[5]; int main(){ cin >> n >> bag; for(i=0;i<n;i++){ cin >> w[i] >> v[i]; } for(i=0;i<=3;i++){ index[i] = 1; } for(i=0;i<n;i++){ for(num = 0;num <= 3;num ++){ if(w[i] == w[0] + num){ dp[num][index[num]++] = v[i]; } } } for(num=0;num<=3;num++){ sort(dp[num] + 1,dp[num] + index[num] + 1); reverse(dp[num] + 1,dp[num] + index[num] + 1); } for(i=0;i<=3;i++){ for(j=1;j<=index[i];j++){ dp[i][j] += dp[i][j-1]; //pe(dp[i][j]); } //el; } for(int num1=0;num1 <= index[0];num1 ++){ for(int num2=0;num2 <= index[1];num2 ++){ for(int num3=0;num3 <= index[2];num3++){ if((bag-w[0]*num1-w[0]*num2-num2-w[0]*num3-2*num3) < 0)continue; ll kosuu = (bag-w[0]*num1-w[0]*num2-num2-w[0]*num3-2*num3) / (w[0] + 3); ll kati = dp[0][num1] + dp[1][num2] + dp[2][num3] + dp[3][kosuu]; ans = max(ans,kati); } } } p(ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | enjapma |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2679 Byte |
Status | CE |
Compile Error
./Main.cpp:82:11: error: ‘ll index [5]’ redeclared as different kind of symbol ll index[5]; ^ In file included from ./Main.cpp:16:0: /usr/include/string.h:482:1: note: previous declaration ‘const char* index(const char*, int)’ index (const char *__s, int __c) __THROW ^ ./Main.cpp: In function ‘int main()’: ./Main.cpp:90:10: error: invalid types ‘<unresolved overloaded function type>[ll {aka long long int}]’ for array subscript index[i] = 1; ^ ./Main.cpp:95:22: error: invalid types ‘<unresolved overloaded function type>[ll {aka long long int}]’ for array subscript dp[num][index[num]++] = v[i]; ^ ./Main.cpp:100:39: error: invalid types ‘<unresolved overloaded function type>[ll {aka long long int}]’ for array subscript sort(dp[num] + 1,dp[num] + index[num] + 1); ^ ./Main.cpp:101:42: error: invalid types ‘<unresolved overloaded function type>[ll {aka long long int}]’ for array subscript reverse(dp[num] + 1,dp[nu...