提出 #20347402


ソースコード 拡げる

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; ll X, A[101];
ll dp[101][101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> X;
	rep(i, 0, N) cin >> A[i];

	ll ans = infl;
	rep(k, 1, N + 1) {
		rep(i, 0, N + 1) rep(use, 0, k + 1) rep(mo, 0, k) dp[i][use][mo] = infl;
		dp[0][0][X % k] = X;

		rep(i, 0, N) rep(use, 0, k + 1) rep(mo, 0, k) if (dp[i][use][mo] != infl) {
			chmin(dp[i + 1][use][mo], dp[i][use][mo]);
			if (use < k) chmin(dp[i + 1][use + 1][(((mo - A[i]) % k) + k) % k], dp[i][use][mo] - A[i]);
		}
		if(dp[N][k][0] != infl) chmin(ans, dp[N][k][0] / k);
	}
	cout << ans << endl;
}





提出情報

提出日時
問題 F - Potion
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1)
得点 600
コード長 1952 Byte
結果 AC
実行時間 413 ms
メモリ 11692 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 34
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, special_01.txt, special_02.txt, special_03.txt, special_04.txt, special_05.txt, special_06.txt, special_07.txt, special_08.txt, special_09.txt, special_10.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 66 ms 11616 KiB
hand_02.txt AC 62 ms 11584 KiB
random_01.txt AC 408 ms 11580 KiB
random_02.txt AC 2 ms 3604 KiB
random_03.txt AC 407 ms 11656 KiB
random_04.txt AC 43 ms 6100 KiB
random_05.txt AC 406 ms 11680 KiB
random_06.txt AC 334 ms 11196 KiB
random_07.txt AC 404 ms 11652 KiB
random_08.txt AC 3 ms 4036 KiB
random_09.txt AC 408 ms 11564 KiB
random_10.txt AC 5 ms 4144 KiB
random_11.txt AC 413 ms 11572 KiB
random_12.txt AC 9 ms 4176 KiB
random_13.txt AC 408 ms 11652 KiB
random_14.txt AC 49 ms 6144 KiB
random_15.txt AC 407 ms 11652 KiB
random_16.txt AC 24 ms 5228 KiB
random_17.txt AC 406 ms 11584 KiB
random_18.txt AC 6 ms 4140 KiB
random_19.txt AC 408 ms 11584 KiB
random_20.txt AC 9 ms 4312 KiB
sample_01.txt AC 2 ms 3492 KiB
sample_02.txt AC 2 ms 3572 KiB
special_01.txt AC 66 ms 11528 KiB
special_02.txt AC 68 ms 11572 KiB
special_03.txt AC 76 ms 11692 KiB
special_04.txt AC 82 ms 11684 KiB
special_05.txt AC 86 ms 11576 KiB
special_06.txt AC 87 ms 11688 KiB
special_07.txt AC 95 ms 11628 KiB
special_08.txt AC 97 ms 11648 KiB
special_09.txt AC 104 ms 11652 KiB
special_10.txt AC 106 ms 11648 KiB