Skip to content

Commit 7dfa0ee

Browse files
authored
Merge pull request #506 from xirc/atcoder/abc181
AtCoder/ABC181
2 parents 53e6037 + baa7f49 commit 7dfa0ee

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

atcoder/abc181/A/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
14+
auto color = (N % 2 == 0) ? "White" : "Black";
15+
cout << color << endl;
16+
17+
return 0;
18+
}

atcoder/abc181/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 = 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+
13+
cin >> N;
14+
15+
ll sum = 0;
16+
for (int i = 0; i < N; ++i) {
17+
int A, B;
18+
cin >> A >> B;
19+
sum += ll(A + B) * (B - A + 1) / 2;
20+
}
21+
cout << sum << endl;
22+
23+
return 0;
24+
}

atcoder/abc181/C/main.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N;
8+
vector<int> xs, ys;
9+
10+
bool solve() {
11+
for (int i = 0; i < N; ++i) {
12+
for (int j = 0; j < N; ++j) {
13+
if (i == j) continue;
14+
for (int k = 0; k < N; ++k) {
15+
if (k == i || k == j) continue;
16+
int lhs = (ys[j] - ys[i]) * (xs[k] - xs[j]);
17+
int rhs = (ys[k] - ys[j]) * (xs[j] - xs[i]);
18+
if (lhs == rhs) return true;
19+
}
20+
}
21+
}
22+
return false;
23+
}
24+
25+
int main() {
26+
ios_base::sync_with_stdio(false);
27+
cin.tie(0); cout.tie(0);
28+
29+
cin >> N;
30+
xs.assign(N, 0);
31+
ys.assign(N, 0);
32+
for (int i = 0; i < N; ++i) {
33+
cin >> xs[i] >> ys[i];
34+
}
35+
36+
auto ans = solve() ? "Yes" : "No";
37+
cout << ans << endl;
38+
39+
return 0;
40+
}

atcoder/abc181/D/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+
bool solve(string const& S) {
8+
vector<int> count(10, 0);
9+
for (auto c : S) {
10+
int i = c - '0';
11+
count[i] = min(3, count[i]+1);
12+
}
13+
14+
vector<int> xs;
15+
for (int i = 0; i < 10; ++i) {
16+
while (count[i] > 0) {
17+
xs.push_back(i);
18+
--count[i];
19+
}
20+
}
21+
22+
int const M = xs.size();
23+
assert(M >= 1);
24+
if (M == 1) {
25+
return xs[0] % 8 == 0;
26+
}
27+
if (M == 2) {
28+
int s1 = xs[0] * 10 + xs[1];
29+
int s2 = xs[1] * 10 + xs[0];
30+
return (s1 % 8 == 0 || s2 % 8 == 0);
31+
}
32+
for (int i = 0; i < M; ++i) {
33+
for (int j = 0 ; j < M; ++j) {
34+
if (i == j) continue;
35+
for (int k = 0; k < M; ++k) {
36+
if (k == i || k == j) continue;
37+
int s = xs[i] * 100 + xs[j] * 10 + xs[k];
38+
if (s % 8 == 0) return true;
39+
}
40+
}
41+
}
42+
return false;
43+
}
44+
45+
int main() {
46+
ios_base::sync_with_stdio(false);
47+
cin.tie(0); cout.tie(0);
48+
49+
string S;
50+
cin >> S;
51+
auto ans = solve(S) ? "Yes" : "No";
52+
cout << ans << endl;
53+
54+
return 0;
55+
}

atcoder/abc181/E/main.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+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, M;
8+
vector<int> H;
9+
vector<int> W;
10+
11+
ll solve() {
12+
sort(H.begin(), H.end());
13+
sort(W.begin(), W.end());
14+
W.erase(unique(W.begin(), W.end()), W.end());
15+
16+
vector<ll> L(N, 0), R(N, 0);
17+
for (int i = 1; i < N; i += 2) {
18+
L[i] = (i-2 > 0) ? L[i-2] : 0;
19+
L[i] += H[i] - H[i-1];
20+
}
21+
for (int i = N - 2; i >= 0; i -= 2) {
22+
R[i] = (i+2 < N) ? R[i+2] : 0;
23+
R[i] += H[i+1] - H[i];
24+
}
25+
26+
ll ans = numeric_limits<ll>::max();
27+
for (int i = 0; i < N; i += 2) {
28+
ll ls = (i-1 >= 0) ? L[i-1] : 0;
29+
ll rs = (i+1 < N) ? R[i+1] : 0;
30+
auto lb = lower_bound(W.begin(), W.end(), H[i]);
31+
if (lb != W.end()) {
32+
ans = min(ans, ls + rs + (*lb - H[i]));
33+
}
34+
auto ub = upper_bound(W.begin(), W.end(), H[i]);
35+
if (ub != W.begin()) {
36+
--ub;
37+
ans = min(ans, ls + rs + (H[i] - *ub));
38+
}
39+
}
40+
41+
return ans;
42+
}
43+
44+
int main() {
45+
ios_base::sync_with_stdio(false);
46+
cin.tie(0); cout.tie(0);
47+
48+
cin >> N >> M;
49+
50+
H.assign(N, 0);
51+
for (auto &h : H) cin >> h;
52+
W.assign(M, 0);
53+
for (auto &w : W) cin >> w;
54+
cout << solve() << endl;
55+
56+
return 0;
57+
}

0 commit comments

Comments
 (0)