Skip to content

Commit f5a2664

Browse files
authored
Merge pull request #511 from xirc/atcoder/abc188
AtCoder/ABC188
2 parents 6a353b4 + 3294527 commit f5a2664

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

atcoder/abc188/A/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int X, Y;
12+
cin >> X >> Y;
13+
bool ans = abs(X - Y) < 3;
14+
cout << (ans ? "Yes" : "No") << endl;
15+
16+
return 0;
17+
}

atcoder/abc188/B/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int N;
12+
cin >> N;
13+
vector<int> A(N), B(N);
14+
for (auto &a : A) cin >> a;
15+
for (auto &b : B) cin >> b;
16+
17+
ll ip = 0;
18+
for (int i = 0; i < N; ++i) {
19+
ip += A[i] * B[i];
20+
}
21+
bool ans = ip == 0;
22+
cout << (ans ? "Yes" : "No") << endl;
23+
24+
return 0;
25+
}

atcoder/abc188/C/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int main() {
8+
ios_base::sync_with_stdio(false);
9+
cin.tie(0); cout.tie(0);
10+
11+
int N, M;
12+
vector<int> A;
13+
14+
cin >> N;
15+
M = 1 << N;
16+
A.assign(M, 0);
17+
for (int i = 0; i < M; ++i) {
18+
cin >> A[i];
19+
}
20+
21+
M /= 2;
22+
auto l = distance(A.begin(), max_element(A.begin(), A.begin() + M));
23+
auto r = distance(A.begin(), max_element(A.begin() + M, A.end()));
24+
int ans = (A[l] < A[r]) ? l : r;
25+
cout << (ans+1) << endl;
26+
27+
return 0;
28+
}

atcoder/abc188/D/main.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+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, C;
8+
vector<int> as, bs, cs;
9+
10+
ll solve() {
11+
vector<pair<int,int>> events;
12+
for (int i = 0; i < N; ++i) {
13+
events.push_back(make_pair(as[i], cs[i]));
14+
events.push_back(make_pair(bs[i]+1, -cs[i]));
15+
}
16+
sort(events.begin(), events.end());
17+
18+
int time = 0;
19+
ll charge_per_day = 0;
20+
ll total_charge = 0;
21+
for (auto const& event : events) {
22+
int t, charge;
23+
tie(t, charge) = event;
24+
total_charge += (t - time) * min(ll(C), charge_per_day);
25+
charge_per_day += charge;
26+
time = t;
27+
}
28+
return total_charge;
29+
}
30+
31+
int main() {
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(0); cout.tie(0);
34+
35+
cin >> N >> C;
36+
as.assign(N, 0);
37+
bs.assign(N, 0);
38+
cs.assign(N, 0);
39+
for (int i = 0; i < N; ++i) {
40+
cin >> as[i] >> bs[i] >> cs[i];
41+
}
42+
cout << solve() << endl;
43+
44+
return 0;
45+
}

atcoder/abc188/E/main.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, M;
8+
vector<int> A;
9+
vector<vector<int>> G;
10+
11+
int ans;
12+
vector<bool> done;
13+
vector<int> maxi;
14+
void dfs(int v) {
15+
if (done[v]) return;
16+
done[v] = true;
17+
maxi[v] = A[v];
18+
for (int u : G[v]) {
19+
dfs(u);
20+
ans = max(ans, maxi[u] - A[v]);
21+
maxi[v] = max(maxi[u], maxi[v]);
22+
}
23+
}
24+
25+
int solve() {
26+
ans = numeric_limits<int>::lowest();
27+
done.assign(N, 0);
28+
maxi.assign(N, numeric_limits<int>::lowest());
29+
for (int v = 0; v < N; ++v) {
30+
if (done[v]) continue;
31+
dfs(v);
32+
}
33+
return ans;
34+
}
35+
36+
int main() {
37+
ios_base::sync_with_stdio(false);
38+
cin.tie(0); cout.tie(0);
39+
40+
cin >> N >> M;
41+
A.assign(N, 0);
42+
for (int i = 0; i < N; ++i) {
43+
cin >> A[i];
44+
}
45+
G.assign(N, {});
46+
for (int i = 0; i < M; ++i) {
47+
int a, b;
48+
cin >> a >> b;
49+
--a, --b;
50+
G[a].push_back(b);
51+
}
52+
cout << solve() << endl;
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)