Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ffabe1d

Browse files
committed
지형편집
1 parent 951435c commit ffabe1d

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

‎gngsn/programmers/스킬트리.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// main.cpp
3+
// 211130-01
4+
//
5+
// Created by 박경선 on 2021年11月30日.
6+
//
7+
8+
#include <iostream>
9+
#include <vector>
10+
#include <climits>
11+
#include <algorithm>
12+
13+
using namespace std;
14+
15+
long long solution(vector<vector<int>> land, int P, int Q) {
16+
long long answer = LLONG_MAX;
17+
vector<long long> flat;
18+
long long total = 0;
19+
long long prev = -1, block = 0;
20+
21+
for (int i = 0; i < land.size(); i++) {
22+
for (int j = 0; j < land[i].size(); j++) {
23+
flat.push_back(land[i][j]);
24+
total+= land[i][j];
25+
}
26+
}
27+
28+
sort(flat.begin(), flat.end());
29+
30+
for (int cur = 0; cur < flat.size(); cur++) {
31+
if (prev != flat[cur]) {
32+
long long add = flat[cur] * cur - block;
33+
long long remove = total - (flat.size() * flat[cur]) + add;
34+
long long cost = add * P + remove * Q;
35+
36+
if (answer > cost) answer = cost;
37+
prev = flat[cur];
38+
}
39+
block += flat[cur];
40+
}
41+
42+
return answer;
43+
}
44+
int main(int argc, const char * argv[]) {
45+
long long result = solution({{4, 4, 3}, {3, 2, 2}, { 2, 1, 0}}, 5, 3);
46+
cout << "result : " << result;
47+
return 0;
48+
}

‎gngsn/programmers/지형편집.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// main.cpp
3+
// 211130-01
4+
//
5+
// Created by 박경선 on 2021年11月30日.
6+
//
7+
8+
#include <iostream>
9+
#include <vector>
10+
#include <climits>
11+
#include <algorithm>
12+
13+
using namespace std;
14+
15+
long long solution(vector<vector<int>> land, int P, int Q) {
16+
long long answer = LLONG_MAX;
17+
vector<long long> flat;
18+
long long total = 0;
19+
long long prev = -1, block = 0;
20+
21+
for (int i = 0; i < land.size(); i++) {
22+
for (int j = 0; j < land[i].size(); j++) {
23+
flat.push_back(land[i][j]);
24+
total+= land[i][j];
25+
}
26+
}
27+
28+
sort(flat.begin(), flat.end());
29+
30+
for (int cur = 0; cur < flat.size(); cur++) {
31+
if (prev != flat[cur]) {
32+
long long add = flat[cur] * cur - block;
33+
long long remove = total - (flat.size() * flat[cur]) + add;
34+
long long cost = add * P + remove * Q;
35+
36+
if (answer > cost) answer = cost;
37+
prev = flat[cur];
38+
}
39+
block += flat[cur];
40+
}
41+
42+
return answer;
43+
}
44+
int main(int argc, const char * argv[]) {
45+
long long result = solution({{4, 4, 3}, {3, 2, 2}, { 2, 1, 0}}, 5, 3);
46+
cout << "result : " << result;
47+
return 0;
48+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /