답안 #709239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709239 2023-03-13T09:14:58 Z minhcool Sightseeing in Kyoto (JOI22_kyoto) C++17
10 / 100
11 ms 12276 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;
const int mod = 1e9 + 7, oo = 1e18 + 7;

int n, m;
int r[N], c[N];

int arr[5005][5005];

map<int, int> mp;

vector<int> pos1, pos2;

void process(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> r[i];
    for(int i = 1; i <= m; i++) cin >> c[i];
    for(int i = 1; i <= n; i++){
    	if(mp[r[i]]) continue;
    	mp[r[i]] = i;
    	pos1.pb(i);
	}
	mp.clear();
	for(int i = n; i >= 1; i--){
		if(mp[r[i]]) continue;
		mp[r[i]] = i;
		pos1.pb(i);
	}
	mp.clear();
	for(int i = 1; i <= m; i++){
		if(mp[c[i]]) continue;
		mp[c[i]] = i;
		pos2.pb(i);
	}
	for(int i = m; i >= 1; i--){
		if(mp[c[i]]) continue;
		mp[c[i]] = i;
		pos2.pb(i);
	}
	pos1.pb(1), pos1.pb(n), pos2.pb(1), pos2.pb(m);
	sort(pos1.begin(), pos1.end());
	pos1.resize(unique(pos1.begin(), pos1.end()) - pos1.begin());
	sort(pos2.begin(), pos2.end());
	pos2.resize(unique(pos2.begin(), pos2.end()) - pos2.begin());
    for(int i = 0; i < pos1.size(); i++){
    	for(int j = 0; j < pos2.size(); j++) arr[i][j] = oo;
	}
	arr[0][0] = 0;
	for(int i = 1; i < pos2.size(); i++) arr[0][i] = r[pos1[0]] * (pos2[i] - 1);
	for(int i = 1; i < pos1.size(); i++) arr[i][0] = c[pos2[0]] * (pos1[i] - 1); 
	for(int i = 1; i < pos1.size(); i++){
		for(int j = 1; j < pos2.size(); j++){
			arr[i][j] = min(arr[i][j - 1] + r[pos1[i]] * (pos2[j] - pos2[j - 1]), arr[i - 1][j] + c[pos2[j]] * (pos1[i] - pos1[i - 1])); 
		}
	}
	/*
	for(int i = 0; i < pos1.size(); i++){
		for(int j = 0; j < pos2.size(); j++) cout << arr[i][j] << " ";
		cout << "\n";
	}*/
	cout << arr[pos1.size() - 1][pos2.size() - 1];
}

signed main(){
    ios_base::sync_with_stdio(0);
    //freopen("KEK.inp", "r", stdin);
    //freopen("KEK.out", "w", stdout);
    cin.tie(0);
    process();
}

Compilation message

kyoto.cpp: In function 'void process()':
kyoto.cpp:56:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0; i < pos1.size(); i++){
      |                    ~~^~~~~~~~~~~~~
kyoto.cpp:57:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |      for(int j = 0; j < pos2.size(); j++) arr[i][j] = oo;
      |                     ~~^~~~~~~~~~~~~
kyoto.cpp:60:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i = 1; i < pos2.size(); i++) arr[0][i] = r[pos1[0]] * (pos2[i] - 1);
      |                 ~~^~~~~~~~~~~~~
kyoto.cpp:61:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 1; i < pos1.size(); i++) arr[i][0] = c[pos2[0]] * (pos1[i] - 1);
      |                 ~~^~~~~~~~~~~~~
kyoto.cpp:62:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i = 1; i < pos1.size(); i++){
      |                 ~~^~~~~~~~~~~~~
kyoto.cpp:63:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int j = 1; j < pos2.size(); j++){
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 976 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 11 ms 12240 KB Output is correct
10 Correct 11 ms 12264 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 11 ms 12244 KB Output is correct
13 Correct 10 ms 12276 KB Output is correct
14 Correct 10 ms 12244 KB Output is correct
15 Correct 11 ms 12244 KB Output is correct
16 Correct 10 ms 12244 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 3 ms 3284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 976 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 11 ms 12240 KB Output is correct
10 Correct 11 ms 12264 KB Output is correct
11 Correct 10 ms 12244 KB Output is correct
12 Correct 11 ms 12244 KB Output is correct
13 Correct 10 ms 12276 KB Output is correct
14 Correct 10 ms 12244 KB Output is correct
15 Correct 11 ms 12244 KB Output is correct
16 Correct 10 ms 12244 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 3 ms 3284 KB Output isn't correct
32 Halted 0 ms 0 KB -