답안 #1069059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069059 2024-08-21T15:23:06 Z prvocislo Giraffes (JOI22_giraffes) C++17
59 / 100
2391 ms 225364 KB
// Is it a wonder I broke? Let's hear one more joke
// Then we could all just laugh until I cry
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
typedef long long ll;
using namespace std;

const int maxn = 305;
int dp[maxn][maxn][maxn]; // interval co ostava, zaciatok hodnot, max pocet tych co si mozeme nechat

void upd(int& a, int b) { a = max(a, b); }

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i], p[i]--;
	int ans = 0;
	for (int l = 0; l < n; l++) for (int r = n - 1; r >= l; r--)
	{
		for (int vl = 0; vl + (r - l) < n; vl++)
		{
			int vr = vl + r - l;
			if (l == r)
			{
				if (p[l] == vr) upd(ans, dp[l][r][vl] + 1);
				upd(ans, dp[l][r][vl]);
				continue;
			}
			upd(dp[l + 1][r][vl + 1], dp[l][r][vl] + (p[l] == vl));
			upd(dp[l][r - 1][vl + 1], dp[l][r][vl] + (p[r] == vl));
			upd(dp[l + 1][r][vl], dp[l][r][vl] + (p[l] == vr));
			upd(dp[l][r - 1][vl], dp[l][r][vl] + (p[r] == vr));
		}
	}
	cout << n - ans << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 4 ms 6236 KB Output is correct
23 Correct 14 ms 21660 KB Output is correct
24 Correct 27 ms 36352 KB Output is correct
25 Correct 44 ms 51536 KB Output is correct
26 Correct 47 ms 53840 KB Output is correct
27 Correct 47 ms 54352 KB Output is correct
28 Correct 52 ms 54608 KB Output is correct
29 Correct 48 ms 54864 KB Output is correct
30 Correct 51 ms 55376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 4 ms 6236 KB Output is correct
23 Correct 14 ms 21660 KB Output is correct
24 Correct 27 ms 36352 KB Output is correct
25 Correct 44 ms 51536 KB Output is correct
26 Correct 47 ms 53840 KB Output is correct
27 Correct 47 ms 54352 KB Output is correct
28 Correct 52 ms 54608 KB Output is correct
29 Correct 48 ms 54864 KB Output is correct
30 Correct 51 ms 55376 KB Output is correct
31 Runtime error 2391 ms 225364 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -