Skip to content

Commit 28c546b

Browse files
committed
atcoder beginner round 119
1 parent f71609c commit 28c546b

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed

atcoder/beginner/119/A.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
string s;
9+
10+
getline(cin, s, '/');
11+
int year = stoi(s);
12+
13+
getline(cin, s, '/');
14+
int month = stoi(s);
15+
16+
getline(cin, s);
17+
int day = stoi(s);
18+
19+
if(year > 2019) cout << "TBD\n";
20+
else if(year < 2019) cout << "Heisei\n";
21+
else
22+
{
23+
if(month > 4) cout << "TBD\n";
24+
else if(month < 4) cout << "Heisei\n";
25+
else
26+
{
27+
if(day > 30) cout << "TBD\n";
28+
else cout << "Heisei\n";
29+
}
30+
}
31+
}

atcoder/beginner/119/B.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
double total;
7+
string s;
8+
int n;
9+
10+
int main()
11+
{
12+
cin >> n;
13+
for(int i = 0; i < n; i++)
14+
{
15+
double val;
16+
cin >> val >> s;
17+
if(s == "JPY") total += val;
18+
else total += val * 380000.0;
19+
}
20+
21+
printf("%.6f\n", total);
22+
}

atcoder/beginner/119/C.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
#include <cmath>
3+
#include <vector>
4+
5+
using namespace std;
6+
7+
int visited[10];
8+
int ans, n, num[10], check[4];
9+
10+
int checkValue()
11+
{
12+
int ret = 0;
13+
int cnt[4] = { 0, 0, 0, 0 };
14+
int arr[4] = { 0, 0, 0, 0 };
15+
for(int i = 0; i < n; i++)
16+
{
17+
arr[visited[i]] += num[i];
18+
cnt[visited[i]]++;
19+
}
20+
21+
for(int i = 1; i < 4; i++)
22+
{
23+
if(arr[i] == 0) return 100000;
24+
ret += abs(arr[i] - check[i]) + 10 * (cnt[i] - 1);
25+
}
26+
27+
return ret;
28+
}
29+
30+
void dfs(int depth)
31+
{
32+
if(depth == n)
33+
{
34+
int val = checkValue();
35+
36+
ans = min(ans, val);
37+
}
38+
else
39+
{
40+
visited[depth] = 0;
41+
dfs(depth + 1);
42+
visited[depth] = 1;
43+
dfs(depth + 1);
44+
visited[depth] = 2;
45+
dfs(depth + 1);
46+
visited[depth] = 3;
47+
dfs(depth + 1);
48+
}
49+
}
50+
51+
int main()
52+
{
53+
cin >> n;
54+
for(int i = 1; i <= 3; i++) cin >> check[i];
55+
for(int i = 0; i < n; i++) cin >> num[i];
56+
57+
ans = 100000;
58+
dfs(0);
59+
cout << ans << '\n';
60+
}

atcoder/beginner/119/D.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
4+
using namespace std;
5+
6+
typedef long long ll;
7+
8+
int a, b, q;
9+
ll s[100002], t[100002], x;
10+
11+
ll binary1(int start, int end, ll find, ll arr[])
12+
{
13+
while(start + 1 < end)
14+
{
15+
int mid = (start + end) / 2;
16+
ll val = arr[mid];
17+
18+
if(val > find) end = mid - 1;
19+
else start = mid;
20+
}
21+
22+
if(arr[end] <= find) return end;
23+
else return start;
24+
}
25+
26+
ll binary2(int start, int end, ll find, ll arr[])
27+
{
28+
while(start < end)
29+
{
30+
int mid = (start + end) / 2;
31+
ll val = arr[mid];
32+
33+
if(val < find) start = mid + 1;
34+
else end = mid;
35+
}
36+
37+
return end;
38+
}
39+
40+
ll min(ll l1, ll l2)
41+
{
42+
return l1 < l2 ? l1 : l2;
43+
}
44+
45+
ll max(ll l1, ll l2)
46+
{
47+
return l1 < l2 ? l2 : l1;
48+
}
49+
50+
int main()
51+
{
52+
cin.tie(NULL);
53+
54+
cin >> a >> b >> q;
55+
for(int i = 0; i < a; i++) cin >> s[i];
56+
for(int i = 0; i < b; i++) cin >> t[i];
57+
58+
for(int i = 0; i < q; i++)
59+
{
60+
ll ans;
61+
cin >> x;
62+
63+
ll sl = s[binary1(0, a - 1, x, s)], sr = s[binary2(0, a - 1, x, s)];
64+
ll tl = t[binary1(0, b - 1, x, t)], tr = t[binary2(0, b - 1, x, t)];
65+
66+
ans = abs(sl - x) + abs(sl - tr);
67+
ans = min(ans, abs(tr - x) + abs(sl - tr));
68+
ans = min(ans, abs(sr - x) + abs(sr - tl));
69+
ans = min(ans, abs(tl - x) + abs(sr - tl));
70+
71+
if(sl <= x && tl <= x)
72+
{
73+
ans = min(ans, abs(min(sl, tl) - x));
74+
}
75+
76+
if(x <= sr && x <= tr)
77+
{
78+
ans = min(ans, abs(max(sr, tr) - x));
79+
}
80+
81+
cout << ans << '\n';
82+
}
83+
}

0 commit comments

Comments
 (0)