답안 #771956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771956 2023-07-03T12:46:33 Z I_Love_EliskaM_ Exam (eJOI20_exam) C++14
12 / 100
16 ms 2688 KB
//  Esti <3

//\
     šťastia pre nás :)
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\
 
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3","unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")

using ll = long long;
#define int long long
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 1e9+7;//998244353;
 
// \
\
:smiling_face_with_3_hearts: :smiling_face_with_3_hearts:  :smiling_face_with_3_hearts:  
 
//vidime sa veľmi skoro, moje slnko

void p2(vector<int>&a, vector<int>&b, int n) {
	vector<int> vis(n,0);
	int ans=0;
	forn(i,n) {
		if (vis[i]) continue;
		if (a[i]!=b[i]) continue;
		++ans;
		for (int l=i-1; l>=0; --l) {
			if (a[l]>b[l]) break;
			++ans;
		}
		for (int r=i+1; r<n; ++r) {
			if (a[r]>b[r]) break;
			++ans;
			vis[r]=1;
		}
	}
	cout<<ans<<'\n';
	exit(0);
}

const int N=5555;
int dp[N][N];

void p3(vector<int> a, vector<int> b, int n) {
	map<int,int> pos;
	forn(i,n) pos[a[i]]=i;
	forn(i,n) {
		for (int j=i; j<n; ++j) {
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(b[i]==a[j]));
			if (j) dp[i+1][j]=max(dp[i+1][j],dp[i][j-1]+(b[i]==a[j]));
		}
		//forn(j,n) cout<<dp[i+1][j]<<' '; cout<<'\n';
	}
	cout<<dp[n][n-1]<<'\n';
	exit(1);
}

void solve() {

	int n; cin>>n;
	vii(a,n);
	vii(b,n);

	int z=1; forn(i,n) z&=b[i]==b[0];
	if (z) p2(a,b,n);
	
	z=n<=5000; forn(i,n-1) z&=a[i]<a[i+1];
	if (z) p3(a,b,n);

}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Compilation message

exam.cpp:3:1: warning: multi-line comment [-Wcomment]
    3 | //\
      | ^
exam.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //   \ __ __  \
      | ^
exam.cpp:36:1: warning: multi-line comment [-Wcomment]
   36 | // \
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 11 ms 2392 KB Output is correct
4 Correct 9 ms 2664 KB Output is correct
5 Correct 16 ms 2656 KB Output is correct
6 Correct 9 ms 2644 KB Output is correct
7 Correct 9 ms 2644 KB Output is correct
8 Correct 15 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 340 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -