답안 #468059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468059 2021-08-26T09:53:53 Z Stickfish Exam (eJOI20_exam) C++17
12 / 100
1000 ms 1092 KB
#include <iostream>
#include <set>
using namespace std;

const int MAXN = 1e5 + 123;
int a[MAXN];
int b[MAXN];

void solve_2(int n){
	int cnt = 0;
	int isneeded = 0;
	int ans = 0;
	for(int i = 0; i < n; ++i){
		if(a[i] == b[0]){
			isneeded = 1;
		}
		if(a[i] > b[0]){
			ans += cnt * isneeded;
			isneeded = 0;
			cnt = 0;
		} else {
			++cnt;
		}
	}
	cout << ans + cnt * isneeded << endl;
}

void solve_4(int n){
	
}

int dp_[MAXN];
int* dp = dp_ + 1;

void solve_slow(int n){
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		int mx = a[i];
		for(int j = i; j >= 0; --j){
			mx = max(mx, a[j]);
			int cnt = 0;
			//cout << "--- " << i << ' ' << j << " ---" << endl;
			//cout << mx << ": ";
			for(int k = j; k <= i; ++k){
				if(b[k] == mx){
					++cnt;
				}
				//cout << b[k] << " ";
			}
			//cout << endl;
			dp[i] = max(dp[i], dp[j - 1] + cnt);
		}
	}
	cout << dp[n - 1] << endl;
}

signed main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	for(int i = 0; i < n; ++i)
		cin >> b[i];
	bool sub2 = true;
	for(int i = 0; i < n; ++i){
		if(b[i] != b[0])
			sub2 = false;
	}
	if(sub2){
		solve_2(n);
		return 0;
	}
	bool sub4 = true;
	set<int> st;
	for(int i = 0; i < n; ++i){
		if(st.find(a[i]) != st.end())
			sub4 = false;
		st.insert(a[i]);
	}
	//if(sub4){
		//return 0;
	//}
	solve_slow(n);

}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:73:7: warning: variable 'sub4' set but not used [-Wunused-but-set-variable]
   73 |  bool sub4 = true;
      |       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 17 ms 428 KB Output is correct
3 Correct 56 ms 1012 KB Output is correct
4 Correct 36 ms 988 KB Output is correct
5 Correct 89 ms 1036 KB Output is correct
6 Correct 41 ms 1092 KB Output is correct
7 Correct 43 ms 1068 KB Output is correct
8 Correct 86 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -