Skip to content

Commit e1c88ad

Browse files
committed
Add contest codes
1 parent 0fc3b2b commit e1c88ad

9 files changed

+334
-0
lines changed

ABC_217_A.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
int main() {
6+
string s, t;
7+
cin >> s >> t;
8+
9+
if (s < t)
10+
{
11+
cout << "Yes" << endl;
12+
}
13+
else
14+
{
15+
cout << "No" << endl;
16+
}
17+
}

ABC_217_B.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
int main() {
6+
string a[3];
7+
cin >> a[0] >> a[1] >> a[2];
8+
9+
string as[4] = {"ABC", "ARC", "AGC", "AHC"};
10+
11+
for (int i = 0; i < 4; i++)
12+
{
13+
bool found = false;
14+
for (int j = 0; j < 3; j++)
15+
{
16+
if (as[i] == a[j])
17+
{
18+
found = true;
19+
break;
20+
}
21+
}
22+
23+
if (!found)
24+
{
25+
cout << as[i] << endl;
26+
}
27+
}
28+
}

ABC_217_C.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
int a[200001];
6+
int b[200001];
7+
8+
int main() {
9+
int n;
10+
cin >> n;
11+
for (int i = 1; i <= n; i++)
12+
{
13+
cin >> a[i];
14+
}
15+
16+
for (int i = 1; i <= n; i++)
17+
{
18+
b[a[i]] = i;
19+
}
20+
21+
for (int i = 1; i <= n; i++)
22+
{
23+
cout << b[i] << ' ';
24+
}
25+
cout << endl;
26+
}

ABC_217_D.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <map>
3+
using namespace std;
4+
5+
map<int, int>::const_iterator find(const map<int, int>& items, int value)
6+
{
7+
auto itlow = items.lower_bound(value);
8+
9+
if (itlow->first == value)
10+
return itlow;
11+
else if (itlow != items.cbegin())
12+
return --itlow;
13+
else
14+
return items.cend();
15+
}
16+
17+
int main() {
18+
int l, q;
19+
20+
cin >> l >> q;
21+
22+
map<int, int> m;
23+
24+
m[1] = 0;
25+
m[l] = l;
26+
27+
while (q--)
28+
{
29+
int c, x;
30+
cin >> c >> x;
31+
32+
if (c == 1)
33+
{
34+
m[x] = x;
35+
}
36+
else
37+
{
38+
auto rit = m.lower_bound(x);
39+
auto lit = find(m, x);
40+
41+
cout << (rit->second) - (lit->second) << endl;
42+
}
43+
}
44+
}

ABC_217_E.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <vector>
4+
#include <functional>
5+
using namespace std;
6+
7+
int main() {
8+
int q;
9+
cin >> q;
10+
11+
priority_queue <int, vector<int>, greater<int> > pq;
12+
queue<int> buffer;
13+
14+
while (q--)
15+
{
16+
int a;
17+
cin >> a;
18+
19+
if (a == 1)
20+
{
21+
int x;
22+
cin >> x;
23+
buffer.push(x);
24+
}
25+
else if (a == 2)
26+
{
27+
if (pq.empty())
28+
{
29+
cout << buffer.front() << endl;
30+
buffer.pop();
31+
}
32+
else
33+
{
34+
cout << pq.top() << endl;
35+
pq.pop();
36+
}
37+
}
38+
else
39+
{
40+
while (!buffer.empty())
41+
{
42+
pq.push(buffer.front());
43+
buffer.pop();
44+
}
45+
}
46+
}
47+
}

ABC_221_A.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int main() {
7+
int a, b;
8+
9+
cin >> a >> b;
10+
11+
cout << (1 << (5 * (a- b))) << endl;
12+
}

ABC_221_B.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int main() {
7+
string s, t;
8+
cin >> s >> t;
9+
10+
string ans = "Yes";
11+
12+
int cnt = 0;
13+
14+
for (int i = 0; i < s.length(); i++)
15+
{
16+
if (s[i] == t[i])
17+
{
18+
continue;
19+
}
20+
21+
if (cnt == 1)
22+
{
23+
ans = "No";
24+
break;
25+
}
26+
27+
if (i + 1 < s.length())
28+
{
29+
cnt = 1;
30+
31+
char temp = t[i];
32+
t[i] = t[i + 1];
33+
t[i + 1] = temp;
34+
i--;
35+
}
36+
else
37+
{
38+
ans = "No";
39+
break;
40+
}
41+
}
42+
43+
cout << ans << endl;
44+
}

ABC_221_C.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <functional>
5+
using namespace std;
6+
7+
int strtoi(string s, int idx, int cnt) {
8+
int ret = 0;
9+
for (int i = 0; i < cnt; i++)
10+
{
11+
ret *= 10;
12+
ret += s[idx + i] - '0';
13+
}
14+
return ret;
15+
}
16+
17+
int main() {
18+
string n;
19+
20+
cin >> n;
21+
22+
sort(n.begin(), n.end());
23+
24+
int ans = 0;
25+
26+
do {
27+
28+
for (int k = 0; k < n.length(); k++)
29+
{
30+
int a = 0, b = 0;
31+
32+
for (int i = 0; i < n.length(); i++)
33+
{
34+
if (i < k)
35+
{
36+
a *= 10;
37+
a += n[i] - '0';
38+
}
39+
else
40+
{
41+
b *= 10;
42+
b += n[i] - '0';
43+
}
44+
}
45+
46+
ans = max(ans, a * b);
47+
}
48+
49+
50+
} while (std::next_permutation(n.begin(), n.end()));
51+
52+
53+
cout << ans << endl;
54+
}

ABC_221_D.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <map>
4+
#include <vector>
5+
using namespace std;
6+
7+
int a[200000];
8+
int b[200000];
9+
int results[200001];
10+
bool loggedin[200001];
11+
12+
int main() {
13+
int n;
14+
15+
cin >> n;
16+
17+
// 1 : µé¾î¿È -1: ³ª°¨
18+
map<int, vector<int> > events;
19+
20+
for (int i = 0; i < n; i++)
21+
{
22+
cin >> a[i] >> b[i];
23+
24+
events[a[i]].push_back(i + 1);
25+
events[a[i] + b[i]].push_back(- (i + 1));
26+
}
27+
28+
int cnt = 0;
29+
int prevTime = -1;
30+
31+
for (auto const& x : events)
32+
{
33+
if (prevTime == -1)
34+
{
35+
prevTime = x.first - 1;
36+
}
37+
38+
results[cnt] += x.first - 1 - prevTime;
39+
40+
for (int i = 0; i < x.second.size(); i++)
41+
{
42+
if (x.second[i] > 0)
43+
{
44+
cnt += 1;
45+
}
46+
if (x.second[i] < 0)
47+
{
48+
cnt -= 1;
49+
}
50+
}
51+
52+
results[cnt] += 1;
53+
prevTime = x.first;
54+
55+
}
56+
57+
for (int i = 1; i <= n; i++)
58+
{
59+
cout << results[i] << ' ';
60+
}
61+
cout << endl;
62+
}

0 commit comments

Comments
 (0)