Submission #3728170


Source Code Expand

#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll N,W;
ll w[109],v[109];
map<ll,ll> now;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>W;
    rep(i,N) cin>>w[i]>>v[i];
    
    now[0]=0;
    rep(i,N){
        map<ll,ll> nxt;
        for(auto m:now){
            ll ww=m.first;
            ll vv=m.second;
            chmax(nxt[ww],vv);
            if(ww+w[i]>W) continue;
            chmax(nxt[ww+w[i]],vv+v[i]);
        }
        swap(now,nxt);
    }
    
    ll ans=0;
    for(auto m:now){
        chmax(ans,m.second);
    }
    cout1(ans)
}

Submission Info

Submission Time
Task D - Simple Knapsack
User mensan_fukuhara
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1603 Byte
Status AC
Exec Time 19 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 16
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 2 ms 256 KB
antigreedy1 AC 2 ms 256 KB
antigreedy2 AC 2 ms 256 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
quarter0 AC 19 ms 640 KB
quarter1 AC 15 ms 512 KB
quarter2 AC 5 ms 384 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB
smallw0 AC 1 ms 256 KB
smallw1 AC 1 ms 256 KB
smallw2 AC 3 ms 256 KB