Skip to content

Commit cccd4e6

Browse files
authored
Merge pull request #315 from xirc/atcoder/abc076
AtCoder/ABC076
2 parents 0507993 + d06fb28 commit cccd4e6

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

atcoder/abc076/A/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int main() {
7+
ios_base::sync_with_stdio(false);
8+
cin.tie(0); cout.tie(0);
9+
10+
int R, G;
11+
cin >> R >> G;
12+
cout << (2 * G - R) << endl;
13+
14+
return 0;
15+
}

atcoder/abc076/B/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int solve(int N, int K) {
7+
int v = 1;
8+
for (int i = 0; i < N; ++i) {
9+
int nv1 = v * 2, nv2 = v + K;
10+
v = min(nv1, nv2);
11+
}
12+
return v;
13+
}
14+
15+
int main() {
16+
ios_base::sync_with_stdio(false);
17+
cin.tie(0); cout.tie(0);
18+
19+
int N, K;
20+
cin >> N >> K;
21+
cout << solve(N, K) << endl;
22+
23+
return 0;
24+
}

atcoder/abc076/C/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
string const NOP = "UNRESTORABLE";
7+
string S, T;
8+
9+
bool solve(vector<char>& W, int s) {
10+
for (int i = 0; i < s; ++i) {
11+
if (W[i] == '?') W[i] = 'a';
12+
}
13+
for (int i = 0; i < T.size(); ++i) {
14+
if (W[s+i] == '?') {
15+
W[s+i] = T[i];
16+
}
17+
if (W[s+i] != T[i]) return false;
18+
}
19+
for (int i = s + T.size(); i < S.size(); ++i) {
20+
if (W[i] == '?') W[i] = 'a';
21+
}
22+
return true;
23+
}
24+
25+
string solve() {
26+
for (int i = S.size() - T.size(); i >= 0; --i) {
27+
vector<char> W(S.begin(), S.end());
28+
if (solve(W, i)) return string(W.begin(), W.end());
29+
}
30+
return NOP;
31+
}
32+
33+
int main() {
34+
ios_base::sync_with_stdio(false);
35+
cin.tie(0); cout.tie(0);
36+
37+
cin >> S >> T;
38+
cout << solve() << endl;
39+
40+
return 0;
41+
}

atcoder/abc076/D/main.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int N;
7+
vector<int> ts;
8+
vector<int> vs;
9+
10+
double solve() {
11+
int T = 0;
12+
vector<vector<int>> cs(N);
13+
for (int i = 0; i < N; ++i) {
14+
int l = T, r = T + ts[i], v = vs[i];
15+
cs[i] = { l, r, v };
16+
T += ts[i];
17+
}
18+
cs.push_back({ 0, 0, 0 });
19+
cs.push_back({ T, T, 0 });
20+
const auto minv = [&](double t) {
21+
double res = 100;
22+
for (auto const& c : cs) {
23+
auto l = c[0], r = c[1], v = c[2];
24+
if (t < l) {
25+
res = min(res, v + (l - t));
26+
} else if (t > r) {
27+
res = min(res, v + (t - r));
28+
} else {
29+
res = min(res, double(v));
30+
}
31+
}
32+
return res;
33+
};
34+
35+
double S = 0;
36+
for (int tt = 0; tt < 2 * T; ++tt) {
37+
double t = tt * 0.5, nt = (tt + 1) * 0.5;
38+
double v = minv(t), nv = minv(nt);
39+
S += 0.5 * (v + nv) * 0.5;
40+
}
41+
return S;
42+
}
43+
44+
int main() {
45+
ios_base::sync_with_stdio(false);
46+
cin.tie(0); cout.tie(0);
47+
48+
cin >> N;
49+
ts.assign(N, 0);
50+
vs.assign(N, 0);
51+
for (int i = 0; i < N; ++i) {
52+
cin >> ts[i];
53+
}
54+
for (int i = 0; i < N; ++i) {
55+
cin >> vs[i];
56+
}
57+
cout << fixed << setprecision(3) << solve() << endl;
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)