Skip to content

Commit 2942136

Browse files
authored
Merge pull request #454 from xirc/atcoder/abc143
AtCoder/ABC143
2 parents 3afb2a8 + b5669e0 commit 2942136

File tree

6 files changed

+186
-1
lines changed

6 files changed

+186
-1
lines changed

atcoder/abc143/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 A, B;
12+
cin >> A >> B;
13+
int C = max(0, A - 2 * B);
14+
cout << C << endl;
15+
16+
return 0;
17+
}

atcoder/abc143/B/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;
12+
vector<int> ds;
13+
14+
cin >> N;
15+
ds.assign(N, 0);
16+
for (int i = 0; i < N; ++i) {
17+
cin >> ds[i];
18+
}
19+
int ans = 0;
20+
for (int i = 0; i < N; ++i) {
21+
for (int j = i + 1; j < N; ++j) {
22+
ans += ds[i] * ds[j];
23+
}
24+
}
25+
cout << ans << endl;
26+
27+
return 0;
28+
}

atcoder/abc143/C/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
string S;
13+
cin >> N >> S;
14+
deque<char> cs;
15+
for (auto c : S) {
16+
if (cs.empty() || cs.back() != c) {
17+
cs.push_back(c);
18+
}
19+
}
20+
cout << cs.size() << endl;
21+
22+
return 0;
23+
}

atcoder/abc143/D/main.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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> ls;
9+
10+
ll solve() {
11+
int const LMAX = 2000;
12+
vector<int> acc(LMAX+1, 0);
13+
for (int i = 0; i < N; ++i) {
14+
acc[ls[i]]++;
15+
}
16+
for (int i = 1; i < LMAX+1; ++i) {
17+
acc[i] += acc[i-1];
18+
}
19+
20+
ll ans = 0;
21+
for (int i = 0; i < N; ++i) {
22+
for (int j = 0; j < N; ++j) {
23+
if (i == j) continue;
24+
int a = ls[i], b = ls[j];
25+
// [cmin,cmax]
26+
int cmin = abs(a - b) + 1;
27+
int cmax = a + b -1;
28+
auto m = acc[cmax];
29+
m -= acc[cmin-1];
30+
if (a >= cmin && a <= cmax) --m;
31+
if (b >= cmin && b <= cmax) --m;
32+
ans += m;
33+
}
34+
}
35+
return ans / 6;
36+
}
37+
38+
int main() {
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(0); cout.tie(0);
41+
42+
cin >> N;
43+
ls.assign(N, 0);
44+
for (auto &l : ls) cin >> l;
45+
cout << solve() << endl;
46+
47+
return 0;
48+
}

atcoder/abc143/E/main.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
const ll inf = 1e16;
8+
int N, L;
9+
vector<vector<ll>> G;
10+
11+
void reduce() {
12+
// Floyd Warshall
13+
for (int k = 0; k < N; ++k) {
14+
for (int i = 0; i < N; ++i) {
15+
for (int j = 0; j < N; ++j) {
16+
G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
17+
}
18+
}
19+
}
20+
}
21+
22+
void build() {
23+
for (int i = 0; i < N; ++i) {
24+
G[i][i] = 0;
25+
}
26+
reduce();
27+
for (int i = 0; i < N; ++i) {
28+
for (int j = 0; j < N; ++j) {
29+
if (i == j) G[i][j] = 0;
30+
else if (G[i][j] <= L) G[i][j] = 1;
31+
else G[i][j] = inf;
32+
}
33+
}
34+
reduce();
35+
}
36+
37+
int query(int u, int v) {
38+
if (G[u][v] == inf)
39+
return -1;
40+
return G[u][v] - 1;
41+
}
42+
43+
int main() {
44+
ios_base::sync_with_stdio(false);
45+
cin.tie(0); cout.tie(0);
46+
47+
int M;
48+
cin >> N >> M >> L;
49+
G.assign(N, vector<ll>(N, inf));
50+
for (int i = 0; i < M; ++i) {
51+
int a, b, c;
52+
cin >> a >> b >> c;
53+
--a, --b;
54+
G[a][b] = c;
55+
G[b][a] = c;
56+
}
57+
build();
58+
59+
int Q;
60+
cin >> Q;
61+
for (int i = 0; i < Q; ++i) {
62+
int s, t;
63+
cin >> s >> t;
64+
--s, --t;
65+
cout << query(s, t) << endl;
66+
}
67+
68+
return 0;
69+
}

lib/cpalgo/graph/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ We can find all articulation points of a given graph in `O(V + E)`.
5656
### Challenges
5757
- [正直者の高橋くん - AtCoder ABC021C](https://atcoder.jp/contests/abc021/tasks/abc021_c)
5858
- [Blue Bird - AtCoder ABC022C](https://atcoder.jp/contests/abc022/tasks/abc022_c)
59-
59+
- [Travel by Car - AtCoder ABC143E](https://atcoder.jp/contests/abc143/tasks/abc143_e)
6060

6161
## Bipartite
6262

0 commit comments

Comments
 (0)