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 4225b57

Browse files
committed
Today ps
1 parent d751f69 commit 4225b57

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

‎Baekjoon/Cpp/1339.cpp‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
ll mx(ll a, ll b)
7+
{
8+
return a > b ? a : b;
9+
}
10+
11+
unordered_map<char, int> mp;
12+
vector<char> vc;
13+
14+
bool compare(char &a, char &b)
15+
{
16+
return mp[a] > mp[b];
17+
}
18+
19+
int main()
20+
{
21+
ios::sync_with_stdio(false);
22+
cin.tie(nullptr);
23+
cout.tie(nullptr);
24+
ll n, i, j, x, d, res = 0, mxl = 0;
25+
string s;
26+
vector<string> vs;
27+
char c;
28+
cin >> n;
29+
unordered_set<char> chars;
30+
for (i = 0; i < n; i++)
31+
{
32+
cin >> s;
33+
vs.push_back(s);
34+
mxl = mx(mxl, s.size());
35+
x = s.size();
36+
for (j = 0; j < x; j++)
37+
{
38+
mp[s[j]] = 0;
39+
chars.insert(s[j]);
40+
}
41+
}
42+
d = 1;
43+
for (i = 1; i < mxl; i++)
44+
{
45+
d *= 10;
46+
}
47+
for (i = mxl; i >= 0; i--)
48+
{
49+
for (j = 0; j < n; j++)
50+
{
51+
x = vs[j].size();
52+
if (x < i)
53+
{
54+
continue;
55+
}
56+
mp[vs[j][x - i]] += d;
57+
}
58+
d /= 10;
59+
}
60+
for (auto c : chars)
61+
{
62+
vc.push_back(c);
63+
}
64+
sort(vc.begin(), vc.end(), compare);
65+
x = vc.size();
66+
j = 9;
67+
for (i = 0; i < x; i++)
68+
{
69+
res += mp[vc[i]] * j--;
70+
}
71+
cout << res;
72+
return 0;
73+
}

‎Baekjoon/Cpp/1715.cpp‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int main()
7+
{
8+
ios::sync_with_stdio(false);
9+
cin.tie(nullptr);
10+
cout.tie(nullptr);
11+
int n;
12+
ll res;
13+
cin >> n;
14+
if (n > 1)
15+
{
16+
priority_queue<ll, vector<ll>, greater<ll>> pq;
17+
int x, a, b;
18+
while (n--)
19+
{
20+
cin >> x;
21+
pq.push(x);
22+
}
23+
res = 0;
24+
while (pq.size() > 1)
25+
{
26+
a = pq.top();
27+
pq.pop();
28+
b = pq.top();
29+
pq.pop();
30+
pq.push(a + b);
31+
res += a + b;
32+
}
33+
}
34+
else
35+
{
36+
cin >> res;
37+
}
38+
cout << (n == 1 ? 0 : res);
39+
return 0;
40+
}

0 commit comments

Comments
(0)

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