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 c2ee134

Browse files
committed
Today ps
1 parent c858210 commit c2ee134

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

‎Baekjoon/Cpp/12789.cpp‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios::sync_with_stdio(false);
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
int n, d, v, cur = 1;
11+
stack<int> stk;
12+
cin >> n;
13+
while (n--)
14+
{
15+
cin >> d;
16+
if (cur == d)
17+
{
18+
cur += 1;
19+
continue;
20+
}
21+
while (!stk.empty())
22+
{
23+
v = stk.top();
24+
if (v != cur)
25+
{
26+
break;
27+
}
28+
cur += 1;
29+
stk.pop();
30+
}
31+
stk.push(d);
32+
}
33+
while (!stk.empty())
34+
{
35+
v = stk.top();
36+
if (v != cur)
37+
{
38+
break;
39+
}
40+
cur += 1;
41+
stk.pop();
42+
}
43+
cout << (stk.empty() ? "Nice" : "Sad");
44+
return 0;
45+
}

‎Baekjoon/Cpp/1744.cpp‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios::sync_with_stdio(false);
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
int n, i, d, len, res = 0;
11+
bool zero = false;
12+
vector<int> p_arr, n_arr;
13+
cin >> n;
14+
for (i = 0; i < n; i++)
15+
{
16+
cin >> d;
17+
if (d == 0)
18+
{
19+
zero = true;
20+
}
21+
else if (d > 0)
22+
{
23+
p_arr.push_back(d);
24+
}
25+
else
26+
{
27+
n_arr.push_back(d);
28+
}
29+
}
30+
sort(p_arr.begin(), p_arr.end());
31+
sort(n_arr.begin(), n_arr.end());
32+
len = p_arr.size();
33+
for (i = len - 1; i > 0; i -= 2)
34+
{
35+
if (p_arr[i - 1] == 1 || p_arr[i] == 1)
36+
{
37+
res += p_arr[i] + 1;
38+
continue;
39+
}
40+
res += p_arr[i] * p_arr[i - 1];
41+
}
42+
if (len % 2 == 1)
43+
{
44+
res += p_arr[0];
45+
}
46+
len = n_arr.size();
47+
for (i = 0; i < len - 1; i += 2)
48+
{
49+
res += n_arr[i] * n_arr[i + 1];
50+
}
51+
if (len % 2 == 1 && !zero)
52+
{
53+
res += n_arr[len - 1];
54+
}
55+
cout << res;
56+
return 0;
57+
}

0 commit comments

Comments
(0)

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