結果

問題 No.733 分身並列コーディング
ユーザー FF256grhyFF256grhy
提出日時 2018-09-08 14:45:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,462 ms / 1,500 ms
コード長 2,549 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 169,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 09:11:18
合計ジャッジ時間 30,669 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1,118 ms
4,380 KB
testcase_04 AC 1,093 ms
4,380 KB
testcase_05 AC 1,119 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1,126 ms
4,376 KB
testcase_08 AC 1,120 ms
4,376 KB
testcase_09 AC 382 ms
4,376 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 169 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 437 ms
4,380 KB
testcase_20 AC 464 ms
4,376 KB
testcase_21 AC 156 ms
4,384 KB
testcase_22 AC 1,460 ms
4,380 KB
testcase_23 AC 144 ms
4,376 KB
testcase_24 AC 140 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 1,173 ms
4,380 KB
testcase_29 AC 1,447 ms
4,384 KB
testcase_30 AC 1,462 ms
4,380 KB
testcase_31 AC 1,417 ms
4,380 KB
testcase_32 AC 42 ms
4,384 KB
testcase_33 AC 44 ms
4,376 KB
testcase_34 AC 42 ms
4,380 KB
testcase_35 AC 40 ms
4,380 KB
testcase_36 AC 41 ms
4,380 KB
testcase_37 AC 40 ms
4,384 KB
testcase_38 AC 1,362 ms
4,380 KB
testcase_39 AC 1,319 ms
4,384 KB
testcase_40 AC 1,387 ms
4,380 KB
testcase_41 AC 41 ms
4,376 KB
testcase_42 AC 42 ms
4,380 KB
testcase_43 AC 42 ms
4,380 KB
testcase_44 AC 1,358 ms
4,380 KB
testcase_45 AC 1,382 ms
4,380 KB
testcase_46 AC 1,379 ms
4,380 KB
testcase_47 AC 1,381 ms
4,380 KB
testcase_48 AC 1,386 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }

#define bit(b, i) (((b) >> (i)) & 1)

#define all_comb(b, n, k) for(LU b = (1LLU << (k)) - 1; ! (b >> (n)); \
b = (0 < (k) ? (b | b-1) + (1LLU << (__builtin_popcountll(b ^ ((b | b-1) + 1)) - 2)) : 1LLU << (n)))

// ----

int l, n, t[17], INF = 2000 * 20;

int main() {
	cin >> l >> n;
	inc(i, n) { cin >> t[i]; }
	
	LL ans = 20;
	all_comb(b, n, n / 2) {
		vector<int> v[2];
		inc(i, n) { v[bit(b, i)].PB(t[i]); }
		
		vector<int> dp[2] = {
			vector<int>(1 << v[0].size(), INF), 
			vector<int>(1 << v[1].size(), INF)
		};
		inc(i, 2) { dp[i][0] = 0; }
		
		inc(i, 2) {
		inc(j, dp[i].size()) {
		inc(k,  v[i].size()) {
			if(bit(j, k)) { continue; }
			int p = l - dp[i][j] % l;
			setmin(dp[i][j | (1 << k)], dp[i][j] + v[i][k] + (v[i][k] <= p ? 0 : p));
		}
		}
		}
		
		setmin(ans, ce(dp[0].back() + dp[1].back(), l));
	}
	
	cout << ans << endl;
	
	return 0;
}
0