답안 #1092008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092008 2024-09-22T20:23:06 Z _rain_ Visiting Singapore (NOI20_visitingsingapore) C++14
29 / 100
278 ms 1108 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fixbug false
 
const ll INF = (ll)1e18+7;
const int maxn = 5e3;
int K , n , m ;
ll A , B;
int s[maxn+2] , t[maxn+2] ;
ll v[maxn+2];
 
namespace subtaskfull{
	bool check(){
		return true;
	}
	ll sub(int x1 , int x , int y1 , int y){
		// x for T , y for S
		return A*(x1+y1) + B*(y+x);
	}
	// dp[S][T][MATCH/NOT] 
	ll dpcot[maxn+2] , tamcot[maxn+2] , cot[maxn+2];
	ll dgcheo[maxn+2] , tamcheo[maxn+2];
	ll dp[maxn+2] , f[maxn+2];
	ll ngang[maxn+2]={},tamngang[maxn+2];
	void main_code(){
		memset(dpcot,-0x3f,sizeof dpcot);
		memset(dgcheo,-0x3f,sizeof dgcheo);
		memset(dp,-0x3f,sizeof dp);
		memset(ngang,-0x3f,sizeof ngang);
		for (int i = 0; i <= n; ++i) dp[i] = 0;
		ll ans = -INF;
		for (int layer = 1; layer <= m; ++layer) // T for 
		{
			if (fixbug){
				cout << "(DEBUG)\n";
			}
			for (int i = 0; i <= n; ++i){
				tamcheo[i] = dgcheo[i];
				tamcot[i] = dpcot[i];
				tamngang[i] = ngang[i];
				f[i] = dp[i];
				ngang[i] = dpcot[i] = dgcheo[i] = dp[i] = -INF;
			}
			for (int i = 1; i <= n; ++i) // S for 
			{
				if(s[i]==t[layer])
				{
					dp[i] = max({
						f[i - 1],
						tamcot[i - 1] ,	
						cot[i],
						tamcheo[i-1],
						ngang[i-1]
					}) + v[t[layer]];	
				} 	
				dpcot[i] = max({
					dp[i-1] + sub(1,1,0,0),
					max(tamcot[i],dpcot[i-1]) + sub(0,1,0,0),
					f[i] + sub(1,1,0,0)
				});
				dgcheo[i] = max({ 	
					f[i-1] + sub(1,1,1,1),
					tamcheo[i-1] + sub(0,1,0,1)
				});
				ngang[i] = max({
					ngang[i-1] + sub(0,0,0,1),
					tamcheo[i-1] + sub(0,1,0,1),
					dgcheo[i-1] + sub(0,1,0,0),
					f[i-1] + sub(1,1,1,1),
					tamngang[i] + sub(0,0,0,1)
				});
				if (layer==1) cot[i] += sub(1,1,0,0); else cot[i] += sub(0,1,0,0);
				if (layer==m){
					ans = max({
						ans,dp[i],dgcheo[i],dpcot[i],ngang[i]
					});
				}
				if (fixbug){
					cout << layer << " -- " << i << '\n';
					cout << ngang[i] << ' ' << dpcot[i] << ' ' << dgcheo[i] << ' ' << dp[i] << '\n';
				}
			}
		}
		// for (int i = 1; i <= n; ++i) ans = max(ans,dp[i]);
		cout << ans;
	}
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
 
	cin >> K >> n >> m >> A >> B;
	for (int i = 1; i <= K; ++i) cin >> v[i];
	for (int i = 1; i <= n; ++i) cin >> s[i];
	for (int i = 1; i <= m; ++i) cin >> t[i];
 
	if (subtaskfull::check()){
		subtaskfull::main_code();
		exit(0);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 10 ms 696 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 11 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 8 ms 692 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 11 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 780 KB Output is correct
2 Correct 8 ms 776 KB Output is correct
3 Correct 69 ms 604 KB Output is correct
4 Correct 165 ms 868 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 68 ms 600 KB Output is correct
7 Correct 134 ms 872 KB Output is correct
8 Correct 42 ms 820 KB Output is correct
9 Correct 96 ms 804 KB Output is correct
10 Correct 203 ms 856 KB Output is correct
11 Correct 203 ms 788 KB Output is correct
12 Correct 247 ms 860 KB Output is correct
13 Correct 198 ms 860 KB Output is correct
14 Correct 267 ms 860 KB Output is correct
15 Correct 278 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 780 KB Output is correct
2 Correct 8 ms 776 KB Output is correct
3 Correct 69 ms 604 KB Output is correct
4 Correct 165 ms 868 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 68 ms 600 KB Output is correct
7 Correct 134 ms 872 KB Output is correct
8 Correct 42 ms 820 KB Output is correct
9 Correct 96 ms 804 KB Output is correct
10 Correct 203 ms 856 KB Output is correct
11 Correct 203 ms 788 KB Output is correct
12 Correct 247 ms 860 KB Output is correct
13 Correct 198 ms 860 KB Output is correct
14 Correct 267 ms 860 KB Output is correct
15 Correct 278 ms 860 KB Output is correct
16 Correct 103 ms 856 KB Output is correct
17 Correct 125 ms 1108 KB Output is correct
18 Correct 118 ms 880 KB Output is correct
19 Correct 23 ms 732 KB Output is correct
20 Correct 83 ms 824 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 26 ms 604 KB Output is correct
23 Correct 51 ms 756 KB Output is correct
24 Correct 19 ms 600 KB Output is correct
25 Correct 204 ms 860 KB Output is correct
26 Correct 200 ms 856 KB Output is correct
27 Correct 206 ms 856 KB Output is correct
28 Correct 206 ms 860 KB Output is correct
29 Correct 276 ms 848 KB Output is correct
30 Correct 270 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 780 KB Output is correct
2 Correct 8 ms 776 KB Output is correct
3 Correct 69 ms 604 KB Output is correct
4 Correct 165 ms 868 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 68 ms 600 KB Output is correct
7 Correct 134 ms 872 KB Output is correct
8 Correct 42 ms 820 KB Output is correct
9 Correct 96 ms 804 KB Output is correct
10 Correct 203 ms 856 KB Output is correct
11 Correct 203 ms 788 KB Output is correct
12 Correct 247 ms 860 KB Output is correct
13 Correct 198 ms 860 KB Output is correct
14 Correct 267 ms 860 KB Output is correct
15 Correct 278 ms 860 KB Output is correct
16 Incorrect 178 ms 856 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 10 ms 696 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 11 ms 700 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 8 ms 692 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 11 ms 604 KB Output is correct
21 Correct 20 ms 780 KB Output is correct
22 Correct 8 ms 776 KB Output is correct
23 Correct 69 ms 604 KB Output is correct
24 Correct 165 ms 868 KB Output is correct
25 Correct 52 ms 600 KB Output is correct
26 Correct 68 ms 600 KB Output is correct
27 Correct 134 ms 872 KB Output is correct
28 Correct 42 ms 820 KB Output is correct
29 Correct 96 ms 804 KB Output is correct
30 Correct 203 ms 856 KB Output is correct
31 Correct 203 ms 788 KB Output is correct
32 Correct 247 ms 860 KB Output is correct
33 Correct 198 ms 860 KB Output is correct
34 Correct 267 ms 860 KB Output is correct
35 Correct 278 ms 860 KB Output is correct
36 Correct 103 ms 856 KB Output is correct
37 Correct 125 ms 1108 KB Output is correct
38 Correct 118 ms 880 KB Output is correct
39 Correct 23 ms 732 KB Output is correct
40 Correct 83 ms 824 KB Output is correct
41 Correct 5 ms 604 KB Output is correct
42 Correct 26 ms 604 KB Output is correct
43 Correct 51 ms 756 KB Output is correct
44 Correct 19 ms 600 KB Output is correct
45 Correct 204 ms 860 KB Output is correct
46 Correct 200 ms 856 KB Output is correct
47 Correct 206 ms 856 KB Output is correct
48 Correct 206 ms 860 KB Output is correct
49 Correct 276 ms 848 KB Output is correct
50 Correct 270 ms 860 KB Output is correct
51 Incorrect 178 ms 856 KB Output isn't correct
52 Halted 0 ms 0 KB -