QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688859#5590. Exponent ExchangewavydangRE 2ms82916kbC++171.4kb2024-10-30 13:59:332024-10-30 13:59:33

Judging History

This is the latest submission verdict.

  • [2024-10-30 13:59:33]
  • Judged
  • Verdict: RE
  • Time: 2ms
  • Memory: 82916kb
  • [2024-10-30 13:59:33]
  • Submitted

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int INF = 1e9 + 7;
const int S = 100500;
int dp[101][S][2]; // Change dp array to [n+1][S][2] where n <= 100

void setmin(int& a, int b)
{
	if (a > b) a = b;
}

void solve()
{
	int b, n;
	cin >> b >> n;
	VI v(n);
	FOR(i, 0, n) cin >> v[n - 1 - i]; // Reverse the input order of v

	// Initialize dp array with INF
	FOR(i, 0, n + 1) FOR(j, 0, S) FOR(k, 0, 2) dp[i][j][k] = INF;
	dp[0][0][0] = 0; // Initial state

	int nb = n * b + 1;
	FOR(i, 0, n)
	{
		int d = v[i];
		FOR (s, 0, nb)
		{
			FOR(k, 0, 2)
			{
				if (dp[i][s][k] == INF) continue;
				
				// Update dp for the next state (i+1)
				setmin(dp[i + 1][s + d + k][0], dp[i][s][k]);
				setmin(dp[i + 1][s][1], dp[i][s][k] + b - d - k);
			}
		}
	}

	// Find the minimum transactions needed from the last slice dp[n]
	int ans = nb;
	FOR(s, 0, nb)
	{
		FOR(k, 0, 2)
		{
			ans = min(ans, max(s, dp[n][s][k]));
		}
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9176kb

input:

10 5
4 2 7 8 6

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 0ms
memory: 82916kb

input:

2 100
1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 0ms
memory: 82860kb

input:

2 100
1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 0

output:

20

result:

ok single line: '20'

Test #4:

score: -100
Runtime Error

input:

100 1000
27 21 72 90 53 34 19 36 54 48 74 65 73 50 86 92 85 84 1 57 16 40 16 97 39 62 8 11 31 4 29 56 54 29 59 22 84 65 91 25 94 96 20 30 55 62 17 19 15 40 79 75 2 74 37 53 94 69 57 21 21 39 71 2 50 12 72 98 18 84 38 81 81 11 6 69 49 52 47 25 86 10 72 74 29 16 99 28 8 9 95 62 39 25 3 20 35 20 72 82 ...

output:


result: