Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
set<int> el;
vector<int> ans;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (!el.count(x)) {
ans.push_back(i);
el.insert(x);
}
}
if (int(ans.size()) < k) {
cout << "NO\n";
} else {
cout << "YES\n";
for (int i = 0; i < k; ++i)
cout << ans[i] + 1 << " ";
cout << endl;
}
return 0;
}
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i)
cin >> s[i];
sort(s.begin(), s.end(), [&] (const string &s, const string &t) {
return s.size() < t.size();
});
for (int i = 0; i < n - 1; ++i) {
if (s[i + 1].find(s[i]) == string::npos) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (auto it : s)
cout << it << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int k;
cin >> k;
vector<pair<int, pair<int, int>>> a;
for (int i = 0; i < k; ++i) {
int n;
cin >> n;
vector<int> x(n);
for (int j = 0; j < n; ++j)
cin >> x[j];
int sum = accumulate(x.begin(), x.end(), 0);
for (int j = 0; j < n; ++j)
a.push_back(make_pair(sum - x[j], make_pair(i, j)));
}
stable_sort(a.begin(), a.end());
for (int i = 0; i < int(a.size()) - 1; ++i) {
if (a[i].first == a[i + 1].first && (a[i].second.first != a[i + 1].second.first)) {
cout << "YES" << endl;
cout << a[i + 1].second.first + 1 << " " << a[i + 1].second.second + 1 << endl;
cout << a[i].second.first + 1 << " " << a[i].second.second + 1 << endl;
return 0;
}
}
cout << "NO\n";
return 0;
}
988D - Points and Powers of Two
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> x(n);
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<int> res = { x[0] };
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 31; ++j) {
int lx = x[i] - (1 << j);
int rx = x[i] + (1 << j);
bool isl = binary_search(x.begin(), x.end(), lx);
bool isr = binary_search(x.begin(), x.end(), rx);
if (isl && isr && int(res.size()) < 3) {
res = { lx, x[i], rx };
}
if (isl && int(res.size()) < 2) {
res = { lx, x[i] };
}
if (isl && int(res.size()) < 2) {
res = { x[i], rx };
}
}
}
cout << int(res.size()) << endl;
for (auto it : res)
cout << it << " ";
cout << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
long long n;
cin >> n;
string s = to_string(n);
int ans = INF;
int len = s.size();
for (int i = 0; i < len; ++i) {
for (int j = 0; j < len; ++j) {
if (i == j) continue;
string t = s;
int cur = 0;
for (int k = i; k < len - 1; ++k) {
swap(t[k], t[k + 1]);
++cur;
}
for (int k = j - (j > i); k < len - 2; ++k) {
swap(t[k], t[k + 1]);
++cur;
}
int pos = -1;
for (int k = 0; k < len; ++k) {
if (t[k] != '0') {
pos = k;
break;
}
}
for (int k = pos; k > 0; --k) {
swap(t[k], t[k - 1]);
++cur;
}
long long nn = atoll(t.c_str());
if (nn % 25 == 0)
ans = min(ans, cur);
}
}
if (ans == INF)
ans = -1;
cout << ans << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int a, n, m;
cin >> a >> n >> m;
vector<int> rain(a + 1);
vector<pair<int, int>> umb(a + 1, make_pair(INF, -1));
vector<int> costs(m);
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
for (int j = l; j < r; ++j)
rain[j] = 1;
}
for (int i = 0; i < m; ++i) {
int x, p;
cin >> x >> p;
costs[i] = p;
umb[x] = min(umb[x], make_pair(p, i));
}
vector<vector<int>> dp(a + 1, vector<int>(m + 1, INF));
dp[0][m] = 0;
for (int i = 0; i < a; ++i) {
for (int j = 0; j <= m; ++j) {
if (dp[i][j] == INF)
continue;
if (rain[i] == 0)
dp[i + 1][m] = min(dp[i + 1][m], dp[i][j]);
if (j < m)
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + costs[j]);
if (umb[i].first != INF)
dp[i + 1][umb[i].second] = min(dp[i + 1][umb[i].second], dp[i][j] + umb[i].first);
}
}
int ans = INF;
for (int i = 0; i <= m; ++i)
ans = min(ans, dp[a][i]);
if (ans == INF)
ans = -1;
cout << ans << endl;
return 0;
}