Submission #802119

# Submission time Handle Problem Language Result Execution time Memory
802119 2023-08-02T10:04:49 Z ymm Giraffes (JOI22_giraffes) C++17
59 / 100
7000 ms 93772 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
using namespace std;

const int N = 8192;
short dp[N][N];
short a[N];
int n;

#define MAX(x,y) ((x)>(y)?(x):(y))

__attribute__((optimize("O3,unroll-loops"),target("avx2")))
void up(short len, int l1, int r1, int l2, int r2)
{
	l1 = max(l1, 0);
	l2 = max(l2, 0);
	r1 = min(r1, n-len);
	r2 = min(r2, n-len);
	Loop (i,l1,r1) {
		short ii = i;
		short iil = i + len;
		Loop (j,l2,r2) {
			short x1 = dp[i][j] + (a[j+len] == iil);
			short x2 = dp[i][j+1] + (a[j] == iil);
			short x3 = dp[i+1][j] + (a[j+len] == ii);
			short x4 = dp[i+1][j+1] + (a[j] == ii);
			short x12 = MAX(x1, x2);
			short x34 = MAX(x3, x4);
			short x1234 = MAX(x12, x34);
			dp[i][j] = x1234;
		}
	}
}

const int S = 64;
void Do(int len)
{
	for (int i = 0; i < n-len; i += S) { //for (int j = 0; j < n-len; j += S) {
		for (int k = 0; k < S; k += 1)
			up(len+1+k, i-k, i+S-k, 0, n);//j-k, j+S-k);
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	Loop (i,0,n) {
		cin >> a[i];
		--a[i];
	}
	Loop (i,0,n) Loop (j,0,n)
		dp[i][j] = a[j] == i;
	for (int i = 0; i < n-1; i += S)
		Do(i);
	cout << n-dp[0][0] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 980 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 3 ms 1364 KB Output is correct
26 Correct 3 ms 1492 KB Output is correct
27 Correct 3 ms 1492 KB Output is correct
28 Correct 4 ms 1492 KB Output is correct
29 Correct 3 ms 1492 KB Output is correct
30 Correct 3 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 980 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 3 ms 1364 KB Output is correct
26 Correct 3 ms 1492 KB Output is correct
27 Correct 3 ms 1492 KB Output is correct
28 Correct 4 ms 1492 KB Output is correct
29 Correct 3 ms 1492 KB Output is correct
30 Correct 3 ms 1492 KB Output is correct
31 Correct 570 ms 18924 KB Output is correct
32 Execution timed out 7043 ms 93772 KB Time limit exceeded
33 Halted 0 ms 0 KB -