Skip to content

Commit 6c2198c

Browse files
authored
Merge pull request #401 from xirc/atcoder/abc024
AtCoder/ABC024
2 parents 71f35ed + ba1a3d2 commit 6c2198c

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

atcoder/abc024/A/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 A, B, C, K;
12+
int S, T;
13+
14+
cin >> A >> B >> C >> K;
15+
cin >> S >> T;
16+
17+
if (S + T >= K) {
18+
A -= C;
19+
B -= C;
20+
}
21+
int F = A * S + B * T;
22+
cout << F << endl;
23+
24+
return 0;
25+
}

atcoder/abc024/B/main.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, T;
8+
vector<int> A;
9+
10+
int solve() {
11+
int const M = 2e6;
12+
vector<int> DP(M, 0);
13+
for (int i = 0; i < N; ++i) {
14+
DP[A[i]] += 1;
15+
DP[A[i]+T] -= 1;
16+
}
17+
int ts = 0;
18+
for (int i = 1; i < M; ++i) {
19+
DP[i] += DP[i-1];
20+
}
21+
for (int i = 0; i < M; ++i) {
22+
if (DP[i] > 0) ++ts;
23+
}
24+
return ts;
25+
}
26+
27+
int main() {
28+
ios_base::sync_with_stdio(false);
29+
cin.tie(0); cout.tie(0);
30+
31+
cin >> N >> T;
32+
A.assign(N, 0);
33+
for (int i = 0; i < N; ++i) {
34+
cin >> A[i];
35+
}
36+
cout << solve() << endl;
37+
38+
return 0;
39+
}

atcoder/abc024/C/main.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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, D, K;
12+
vector<int> L, R;
13+
vector<int> S, T;
14+
15+
cin >> N >> D >> K;
16+
L.assign(D, 0);
17+
R.assign(D, 0);
18+
for (int i = 0; i < D; ++i) {
19+
cin >> L[i] >> R[i];
20+
}
21+
S.assign(K, 0);
22+
T.assign(K, 0);
23+
for (int i = 0; i < K; ++i) {
24+
cin >> S[i] >> T[i];
25+
}
26+
27+
vector<int> arrived_day(K, 0);
28+
vector<int> xs(K, 0);
29+
for (int i = 0; i < K; ++i) {
30+
xs[i] = S[i];
31+
}
32+
for (int i = 0; i < D; ++i) {
33+
auto l = L[i], r = R[i];
34+
for (int k = 0; k < K; ++k) {
35+
if (arrived_day[k] > 0) continue;
36+
if (S[k] < T[k] && l <= xs[k]) {
37+
xs[k] = max(xs[k], min(r, T[k]));
38+
if (xs[k] == T[k]) arrived_day[k] = i + 1;
39+
}
40+
if (S[k] > T[k] && xs[k] <= r) {
41+
xs[k] = min(xs[k], max(l, T[k]));
42+
if (xs[k] == T[k]) arrived_day[k] = i + 1;
43+
}
44+
}
45+
}
46+
for (int k = 0; k < K; ++k) {
47+
cout << arrived_day[k] << endl;
48+
}
49+
50+
return 0;
51+
}

atcoder/abc024/D/main.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
3+
inline int64_t extgcd(
4+
int64_t const a,
5+
int64_t const b,
6+
int64_t &x, int64_t &y
7+
)
8+
{
9+
if (b == 0) {
10+
x = 1, y = 0;
11+
return a;
12+
}
13+
int64_t x1, y1;
14+
int64_t g = extgcd(b, a % b, x1, y1);
15+
x = y1;
16+
y = x1 - y1 * (a / b);
17+
return g;
18+
}
19+
20+
inline int64_t modinv(int64_t a, int64_t m) {
21+
int64_t x, y;
22+
int64_t g;
23+
g = extgcd(a, m, x, y);
24+
if (g != 1) {
25+
// There are no modular multiplicative inverse
26+
return -1;
27+
}
28+
return (x % m + m) % m;
29+
}
30+
31+
using namespace std;
32+
using ll = int64_t;
33+
using ff = long double;
34+
35+
int main() {
36+
ios_base::sync_with_stdio(false);
37+
cin.tie(0); cout.tie(0);
38+
39+
ll A, B, C;
40+
cin >> A >> C >> B;
41+
42+
ll const MOD = 1e9+7;
43+
ll cn = (B * C % MOD - A * C % MOD + MOD) % MOD;
44+
ll rn = (B * C % MOD - A * B % MOD + MOD) % MOD;
45+
ll d = (A * B % MOD - B * C % MOD + C * A % MOD + MOD) % MOD;
46+
ll dd = modinv(d, MOD);
47+
ll c = cn * dd % MOD;
48+
ll r = rn * dd % MOD;
49+
50+
cout << r << " " << c << endl;
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)