답안 #918147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918147 2024-01-29T13:16:53 Z KiaRez Exam (eJOI20_exam) C++17
65 / 100
150 ms 199796 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

int t, n, pos[N], a[N], b[N], pd[5005], mx[5005][5005], dp[5005][5005];
vector<int> comp;
int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n;
	if (n > 5000) kill(0);

	for(int i=1; i<=n; i++) cin>>a[i], comp.pb(a[i]);
	for(int i=1; i<=n; i++) cin>>b[i];
	sort(all(comp)); comp.resize(unique(all(comp)) - comp.begin());

	for(int i=1; i<=n; i++) {
		int ptr = lower_bound(all(comp), a[i]) - comp.begin() + 1;
		a[i] = ptr;
		mx[i][i] = a[i];
		ptr = lower_bound(all(comp), b[i]) - comp.begin();
		if(ptr>=0 && ptr<size(comp) && comp[ptr]==b[i]) b[i] = ptr+1;
		else b[i] = 0;
	}

	for(int l=1; l<=n; l++) for(int r=l+1; r<=n; r++) mx[l][r] = max(mx[l][r-1], mx[r][r]);
	for(int i=1; i<=n; i++) dp[1][i] = (b[i]==a[i] && mx[1][i]==a[i]);

	for(int i=1; i<=n; i++) {
		int maxi = 0;
		for(int j=1; j<=n; j++) {
			maxi = max(maxi, dp[i-1][j]);
			if(mx[min(i,j)][max(i,j)] == a[j]) {
				dp[i][j] = maxi + (b[i] == a[j]);
			}
		}
	}

	int ans = 0;
	for(int i=1; i<=n; i++) ans = max(ans, dp[n][i]);
	cout<<ans<<endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8656 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 47732 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 34 ms 86760 KB Output is correct
4 Correct 139 ms 195584 KB Output is correct
5 Correct 149 ms 199508 KB Output is correct
6 Correct 150 ms 199796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8656 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 10704 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 4 ms 14684 KB Output is correct
13 Correct 4 ms 14680 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8656 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 34 ms 86760 KB Output is correct
10 Correct 139 ms 195584 KB Output is correct
11 Correct 149 ms 199508 KB Output is correct
12 Correct 150 ms 199796 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 10704 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 4 ms 14684 KB Output is correct
19 Correct 4 ms 14680 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 13 ms 47708 KB Output is correct
23 Correct 141 ms 199708 KB Output is correct
24 Correct 140 ms 199712 KB Output is correct
25 Correct 144 ms 199616 KB Output is correct
26 Correct 144 ms 199768 KB Output is correct
27 Correct 137 ms 199676 KB Output is correct
28 Correct 142 ms 199504 KB Output is correct
29 Correct 146 ms 199504 KB Output is correct
30 Correct 137 ms 199560 KB Output is correct
31 Correct 142 ms 197976 KB Output is correct
32 Correct 146 ms 198256 KB Output is correct