A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
signed main()
{
IOS;
string a;
cin >> a;
int n = a.size();
if (a[n - 3] == 's' && a[n - 2] == 'a' && a[n - 1] == 'n')
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
}

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
signed main() {
IOS;
string a;
string b;
cin >> a >> b;
if (a == b) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < a.size() && i < b.size(); i++) {
if (a[i] != b[i]) {
cout << i + 1 << endl;
return 0;
}
}
cout << min(a.size(), b.size()) + 1 << endl;

return 0;
}

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
signed main() {
IOS;
int n;
cin >> n;
vector<int> a(n);
int ans = 0;
for (int &v : a) {
cin >> v;
ans += v;
}
int res = 1e18;
for (int i = 0; i < (1 << n); i++)
{
ll sum = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
sum += a[j];
}
}
res = min(res, (int)max(ans - sum, sum));
}
cout << res << endl;
return 0;
}

D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#define MAX 10
double dp[MAX][2];
int n;
double S, T;
double sx[100], sy[100], tx[100], ty[100];
double dis(double x, double y, double xx, double yy)
{
return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
}
signed main()
{
IOS;
cin >> n >> S >> T;
for (int i = 1; i <= n; i++)
{
cin >> sx[i] >> sy[i] >> tx[i] >> ty[i];
}
double ans = 1111111111.0;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
v[i] = i + 1;
}
do
{
double dp[15][2] = {0.0};
for (int op = 0; op < n; op++)
{
int i = v[op];
int j = op ? v[op - 1] : 0;
double len = dis(sx[i], sy[i], tx[i], ty[i]) / T;
dp[i][0] = min(dp[j][0] + dis(sx[j], sy[j], tx[i], ty[i]) / S, dp[j][1] + dis(tx[j], ty[j], tx[i], ty[i]) / S) + len;
dp[i][1] = min(dp[j][0] + dis(sx[j], sy[j], sx[i], sy[i]) / S, dp[j][1] + dis(tx[j], ty[j], sx[i], sy[i]) / S) + len;
//cout << len << ' ' << dp[i][0] << ' ' << dp[i][1] << ' ' << i << ' ' << j << endl;
}
ans = min(ans, (double)min(dp[v[n - 1]][0], dp[v[n - 1]][1]));
//out << ans << endl;
} while (next_permutation(v.begin(), v.end()));
cout << fixed << setprecision(20) << ans << endl;
return 0;
}

E

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
signed main() {
IOS;
int n, x;
cin >> n >> x;

vector<ll> a(n), p(n), b(n), q(n);
for (int i = 0; i < n; i++)
{
cin >> a[i] >> p[i] >> b[i] >> q[i];
if (p[i] * b[i] > q[i] * a[i])
{
swap(a[i], b[i]);
swap(p[i], q[i]);
}
}

auto check = [&](int mid)
{
ll X = x;
for (int i = 0; i < n; i++)
{
ll ans = 1E18;
for (int j = 0; j <= 100; j++)
{
ll s = j * q[i];
ll r = mid - j * b[i];
if (r > 0)
s += (r + a[i] - 1) / a[i] * p[i];

ans = min(ans, s);
}

X -= ans;
if (X < 0)
return false;
}

return true;
};

int l = -1, r = 1E9 + 7;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
cout << r - 1<< endl;

return 0;
}

F

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
signed main() {
IOS;
int n, k, x;
cin >> n >> k >> x;
vector<ll> t(n);
for (ll &a : t)
cin >> a;
vector<ll> clk;
for(ll &a : t) {
for (int i = 0; i <= n; i++) {
clk.push_back(a + i * x);
}
}
sort(clk.begin(), clk.end());
clk.erase(unique(clk.begin(), clk.end()), clk.end());
ll len = clk.size();
vector<vector<ll> > dp(len + 1, vector<ll>(n + 1, 1e18));
dp[0][0] = 0;
ll res = 1e18;
ll nxt = 0;
for (int i = 0; i < len; i++) {
while (nxt < len && clk[nxt] < clk[i] + x) {
nxt++;
}
for (int j = 0; j < n; j++) {
if (dp[i][j] > 1e17) {
continue;
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
ll mv = dp[i][j];
for (ll m = j; m < min(j + k, n); m++) {
if (clk[i] < t[m]) {
break;
}
mv += (clk[i] - t[m]);
if (m == n - 1) {
res = min(res, mv);
} else {
dp[nxt][m + 1] = min(dp[nxt][m + 1], mv);
}
}
}
}
cout << res << '\n';
return 0;
}