답안 #1017806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017806 2024-07-09T10:21:20 Z Unforgettablepl Sightseeing in Kyoto (JOI22_kyoto) C++17
30 / 100
34 ms 34264 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

const int INF = 1e15;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w;
	cin >> h >> w;
	vector<int> a(h+1);
	vector<int> b(w+1);
	for(int i=1;i<=h;i++)cin>>a[i];
	for(int i=1;i<=w;i++)cin>>b[i];
	vector<int> acti={0},actj={0};
	{
		vector<int> maxidx(1001),minidx(1001);
		for(int i=1;i<=h;i++)maxidx[a[i]]=i;
		for(int i=h;i;i--)minidx[a[i]]=i;
		for(int i=1;i<=h;i++)if(i==minidx[a[i]] or i==maxidx[a[i]])acti.emplace_back(i);
	}
	{
		vector<int> maxidx(1001),minidx(1001);
		for(int i=1;i<=w;i++)maxidx[b[i]]=i;
		for(int i=w;i;i--)minidx[b[i]]=i;
		for(int i=1;i<=w;i++)if(i==minidx[b[i]] or i==maxidx[b[i]])actj.emplace_back(i);
	}
	int sh = acti.size()-1;
	int sw = actj.size()-1;
	vector<vector<int>> DP(sh+1,vector<int>(sw+1,INF));
	DP[1][1]=0;
	for(int i=1;i<=sh;i++){
		for(int j=1;j<=sw;j++){
			if(j!=1)DP[i][j]=min(DP[i][j],DP[i][j-1]+(a[acti[i]]*(actj[j]-actj[j-1])));
			if(i!=1)DP[i][j]=min(DP[i][j],DP[i-1][j]+(b[actj[j]]*(acti[i]-acti[i-1])));
		}
	}
	cout << DP[sh][sw] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Runtime error 1 ms 600 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 32 ms 31812 KB Output is correct
5 Correct 5 ms 3160 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 31 ms 34264 KB Output is correct
8 Correct 31 ms 34140 KB Output is correct
9 Correct 32 ms 34220 KB Output is correct
10 Correct 33 ms 34128 KB Output is correct
11 Correct 30 ms 34220 KB Output is correct
12 Correct 34 ms 33692 KB Output is correct
13 Correct 32 ms 33848 KB Output is correct
14 Correct 32 ms 34132 KB Output is correct
15 Correct 10 ms 2908 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 456 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Runtime error 1 ms 600 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -