Skip to content

Commit 03d9443

Browse files
authored
Merge pull request #514 from xirc/atcoder/abc192
AtCoder/ABC192
2 parents cf08786 + 743f133 commit 03d9443

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

atcoder/abc192/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;
12+
cin >> X;
13+
X %= 100;
14+
cout << (100 - X) << endl;
15+
16+
return 0;
17+
}

atcoder/abc192/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+
string S;
12+
cin >> S;
13+
int const N = S.size();
14+
bool difficult = true;
15+
for (int i = 0; i < N; i += 2) {
16+
if (!islower(S[i])) difficult = false;
17+
}
18+
for (int i = 1; i < N; i += 2) {
19+
if (!isupper(S[i])) difficult = false;
20+
}
21+
cout << (difficult ? "Yes" : "No") << endl;
22+
23+
return 0;
24+
}

atcoder/abc192/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+
vector<int> digits(ll x) {
8+
vector<int> xs;
9+
while (x > 0) {
10+
xs.push_back(x % 10);
11+
x /= 10;
12+
}
13+
return xs;
14+
}
15+
16+
ll g1(vector<int>& digits) {
17+
sort(digits.begin(), digits.end(), greater<int>());
18+
ll y = 0;
19+
for (auto d : digits) {
20+
y = y * 10 + d;
21+
}
22+
return y;
23+
}
24+
ll g2(vector<int>& digits) {
25+
sort(digits.begin(), digits.end(), less<int>());
26+
ll y = 0;
27+
for (auto d : digits) {
28+
y = y * 10 + d;
29+
}
30+
return y;
31+
}
32+
ll f(ll x) {
33+
vector<int> xs = digits(x);
34+
return g1(xs) - g2(xs);
35+
}
36+
37+
int main() {
38+
ios_base::sync_with_stdio(false);
39+
cin.tie(0); cout.tie(0);
40+
41+
int N, K;
42+
cin >> N >> K;
43+
44+
ll a = N;
45+
for (int i = 0; i < K; ++i) {
46+
a = f(a);
47+
}
48+
cout << a << endl;
49+
50+
return 0;
51+
}

atcoder/abc192/D/main.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
string X;
8+
ll M;
9+
10+
bool pass(ll n) {
11+
if (n == 0) return true;
12+
ll v = 0;
13+
for (int i = 0; i < X.size(); ++i) {
14+
int x = X[i] - '0';
15+
if (v > M / n) return false;
16+
v *= n;
17+
if (v > M - x) return false;
18+
v += x;
19+
}
20+
return true;
21+
}
22+
23+
int minbase() {
24+
int n = 0;
25+
for (int i = 0; i < X.size(); ++i) {
26+
n = max(n, X[i] - '0');
27+
}
28+
return n + 1;
29+
}
30+
31+
ll maxbase() {
32+
ll ok = 0, ng = 2e18;
33+
while (abs(ok - ng) > 1) {
34+
auto m = (ok + ng) / 2;
35+
if (pass(m)) {
36+
ok = m;
37+
} else {
38+
ng = m;
39+
}
40+
}
41+
return ok;
42+
}
43+
44+
ll solve() {
45+
if (X.size() == 1) {
46+
return (X[0]-'0' <= M) ? 1 : 0;
47+
}
48+
ll mini = minbase();
49+
ll maxi = maxbase();
50+
if (maxi < mini) return 0;
51+
return maxi - mini + 1;
52+
}
53+
54+
int main() {
55+
ios_base::sync_with_stdio(false);
56+
cin.tie(0); cout.tie(0);
57+
58+
cin >> X >> M;
59+
cout << solve() << endl;
60+
61+
return 0;
62+
}

atcoder/abc192/E/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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, X, Y;
8+
vector<vector<array<int,3>>> G;
9+
10+
ll solve() {
11+
using entry = pair<ll,int>;
12+
priority_queue<entry, vector<entry>, greater<entry>> Q;
13+
ll const inf = 1e18;
14+
vector<ll> D(N, inf);
15+
Q.push({ 0, X });
16+
D[X] = 0;
17+
while (Q.size()) {
18+
ll t; int v;
19+
tie(t, v) = Q.top(); Q.pop();
20+
if (v == Y) {
21+
return t;
22+
}
23+
for (auto utk : G[v]) {
24+
int u = utk[0], T = utk[1], K = utk[2];
25+
ll tn = t;
26+
if (tn % K != 0) {
27+
tn += (K - tn % K);
28+
}
29+
if (tn + T < D[u]) {
30+
D[u] = tn + T;
31+
Q.push({ D[u], u });
32+
}
33+
}
34+
}
35+
return -1;
36+
}
37+
38+
int main() {
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(0); cout.tie(0);
41+
42+
cin >> N >> M >> X >> Y;
43+
--X, --Y;
44+
45+
G.assign(N, vector<array<int,3>>());
46+
for (int i = 0; i < M; ++i) {
47+
int A, B, T, K;
48+
cin >> A >> B >> T >> K;
49+
--A, --B;
50+
G[A].push_back({ B, T, K });
51+
G[B].push_back({ A, T, K });
52+
}
53+
cout << solve() << endl;
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)