結果

問題 No.5 数字のブロック
ユーザー pontaryaginpontaryagin
提出日時 2019-04-28 22:41:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,981 ms / 5,000 ms
コード長 5,273 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 123,896 KB
実行使用メモリ 4,816 KB
最終ジャッジ日時 2023-08-23 08:26:16
合計ジャッジ時間 35,532 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,656 KB
testcase_01 AC 6 ms
4,572 KB
testcase_02 AC 3 ms
4,572 KB
testcase_03 AC 1,871 ms
4,628 KB
testcase_04 AC 1,506 ms
4,580 KB
testcase_05 AC 2,398 ms
4,680 KB
testcase_06 AC 1,547 ms
4,668 KB
testcase_07 AC 1,290 ms
4,664 KB
testcase_08 AC 1,765 ms
4,636 KB
testcase_09 AC 617 ms
4,640 KB
testcase_10 AC 2,573 ms
4,640 KB
testcase_11 AC 1,228 ms
4,776 KB
testcase_12 AC 1,929 ms
4,692 KB
testcase_13 AC 2,356 ms
4,680 KB
testcase_14 AC 40 ms
4,576 KB
testcase_15 AC 87 ms
4,816 KB
testcase_16 AC 2,467 ms
4,572 KB
testcase_17 AC 2,891 ms
4,636 KB
testcase_18 AC 2,632 ms
4,696 KB
testcase_19 AC 2,981 ms
4,680 KB
testcase_20 AC 3 ms
4,572 KB
testcase_21 AC 3 ms
4,644 KB
testcase_22 AC 4 ms
4,568 KB
testcase_23 AC 4 ms
4,728 KB
testcase_24 AC 99 ms
4,628 KB
testcase_25 AC 174 ms
4,564 KB
testcase_26 AC 4 ms
4,660 KB
testcase_27 AC 3 ms
4,584 KB
testcase_28 AC 3 ms
4,568 KB
testcase_29 AC 1,446 ms
4,576 KB
testcase_30 AC 713 ms
4,668 KB
testcase_31 AC 3 ms
4,632 KB
testcase_32 AC 3 ms
4,572 KB
testcase_33 AC 3 ms
4,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:9: 警告: #pragma once がメインファイルにあります
   11 | #pragma once
      |         ^~~~

ソースコード

diff #

//#include "MyHeader.h"
//#include "Algorithm.h"
//#include "Bit.h"
//#include "UnionFind.h"
//#include "NumberTheory.h"
//#include "Graph.h"
//#include "SegmentTree.h"
//#include "Dijkstra.h"
//#include "bits/stdc++.h"
#pragma once

#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
#include <type_traits>
#include <array>
#include <cassert>
#include <typeinfo>
#include <time.h>
#include <iomanip>
#include <random>
//#include "boost/variant.hpp"

// #include "bits/stdc++.h"

using namespace std;



#define rep(i, N, M) for(ll i=N, i##_len=(M); i<i##_len; ++i)
#define rep_skip(i, N, M, ...) for(ll i=N, i##_len=(M); i<i##_len; i+=(skip))
#define rrep(i, N, M)  for(ll i=(M)-1, i##_len=(N-1); i>i##_len; --i)
#define pb push_back



typedef pair<double, double> pd;

typedef long long ll;
typedef pair<ll, ll> pll;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 62;

template<int n>
struct tll_impl {
	using type = decltype(tuple_cat(tuple<ll>(), declval<typename tll_impl<n - 1>::type>()));
};
template<>
struct tll_impl<1> {
	using type = tuple<ll>;
};
template<int n>
using tll = typename tll_impl<n>::type;

template<class T>
constexpr ll SZ(T& v) { return static_cast<ll>(v.size()); };


template<int n, typename T>
struct vec_t_impl {
	using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template<typename T>
struct vec_t_impl<1, T> {
	using type = vector<T>;
};
template<int n, typename T>
using vec_t = typename vec_t_impl<n, T>::type;
// check 
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");

// decompose vector into basetype and dimension.
template<typename T>
struct vec_dec {
	static constexpr int dim = 0;
	using type  = T;
};
template<typename T>
struct vec_dec<vector<T>> {
	static constexpr int dim = vec_dec<T>::dim + 1;
	using type  = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
// ex:  auto dp =  make_v<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));

// check if T is vector
template < typename T >
struct is_vector : std::false_type {};

template < typename T >
struct is_vector<vector<T>> : std::true_type {};

template<typename T, typename V>
typename enable_if<!is_vector<T>::value>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_vector<T>::value>::type
fill_v(T& t, const V& v) {
	for (auto&& x : t)
		fill_v(x, v);
}
// ex:  fill_v(dp, INF);

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template<typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) sort(all(c));for(bool c##perm=1;c##perm;c##perm=next_permutation(all(c)))

template<typename T> void chmin(T & a, T b) {
	if (a > b) a = b;
}
template<typename T> void chmax(T & a, T b) {
	if (a < b) a = b;
}

vll seq(ll i, ll j) {
	vll res(j - i);
	rep(k, i, j) res[k] = i + k;
	return res;
}

constexpr ll POW_(ll n, ll m) {
	ll res = 1;
	rep(i, 0, m) {
		res *= n;
	}
	return res;
}

template<ll mod = 0>
constexpr ll POW(ll x, ll n) {
	if (x == 2)
	{
		return (1LL << n) % mod;
	}
	if (n == 0)return 1;
	if (n == 1)return x % mod;
	if (n % 2 == 0)return POW_(POW<mod>(x, n / 2), 2LL) % mod;
	return ((POW_(POW<mod>(x, n / 2), 2LL) % mod) * (x % mod)) % mod;
}
template<>
constexpr ll POW<0>(ll x, ll n) {
	if (x == 2)
	{
		return 1LL << n;
	}
	if (n == 0)return 1;
	if (n == 1)return x;
	if (n % 2 == 0) return POW_(POW(x, n / 2), 2);
	return (POW_(POW(x, n / 2), 2)) * x;
}



template<
	typename Inputs,
	typename Functor,
	typename T = typename Inputs::value_type>
	void sort_by(Inputs & inputs, Functor f) {
	std::sort(std::begin(inputs), std::end(inputs),
		[&f](const T & lhs, const T & rhs) { return f(lhs) < f(rhs); });
}

template<
	typename Inputs,
	typename Functor,
	typename T = typename Inputs::value_type>
	void stable_sort_by(Inputs & inputs, Functor f) {
	std::stable_sort(std::begin(inputs), std::end(inputs),
		[&f](const T & lhs, const T & rhs) { return f(lhs) < f(rhs); });
}


// ============================ Header  =================================

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll l, n;
	cin >> l >> n;
	vll w(n);
	rep(i, 0, n)cin >> w[i];
	ll N = POW(10, 5) * 2;
	vll dp(N,-1);
	dp[0] = 0;
	rep(i, 0, n) {
		rrep(j, 0, N) {
			ll wi = j + w[i];
			if (dp[j] != -1 && wi<= l) {
				dp[wi] = max(dp[wi], dp[j] + 1);
			}
		}
	}
	cout << *max_element(all(dp))<<endl;



	//ll T;
	//cin >> T;
	//rep(test, 1, T + 1) {
	//	[&] {



	//		cout << "Case #" << test << ": " << ok << endl;
	//	}();
	//}



	return 0;

}
0