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> cnt(101);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++cnt[x];
}
cout << *max_element(cnt.begin(), cnt.end()) << endl;
return 0;
}
1003B - Binary String Constructing
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 a, b, x;
cin >> a >> b >> x;
if (x % 2 == 0) {
if (a > b) {
for (int i = 0; i < x / 2; ++i)
cout << "01";
cout << string(b - x / 2, '1');
cout << string(a - x / 2, '0');
} else {
for (int i = 0; i < x / 2; ++i)
cout << "10";
cout << string(a - x / 2, '0');
cout << string(b - x / 2, '1');
}
} else if (a > b) {
for (int i = 0; i < x / 2; ++i)
cout << "01";
cout << string(a - x / 2, '0');
cout << string(b - x / 2, '1');
} else {
for (int i = 0; i < x / 2; ++i)
cout << "10";
cout << string(b - x / 2, '1');
cout << string(a - x / 2, '0');
}
cout << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution (PikMike)
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
return out << "(" << a.x << ", " << a.y << ")";
}
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
out << "[";
forn(i, sz(v)) {
if(i) out << ", ";
out << v[i];
}
return out << "]";
}
mt19937 rnd(time(NULL));
const int INF = int(2e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
const int N = 10000 + 7;
int n, k;
int a[N];
bool read () {
if (scanf("%d%d", &n, &k) != 2)
return false;
forn(i, n) scanf("%d", &a[i]);
return true;
}
int pr[N];
void solve() {
pr[0] = 0;
forn(i, n) pr[i + 1] = pr[i] + a[i];
ld ans = 0;
forn(r, n) forn(l, r + 1){
if (r - l + 1 >= k){
ans = max(ans, (pr[r + 1] - pr[l]) / ld(r - l + 1));
}
}
printf("%.15f\n", double(ans));
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tt = clock();
#endif
cerr.precision(15);
cout.precision(15);
cerr << fixed;
cout << fixed;
while(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
}
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, q;
cin >> n >> q;
vector<int> cnt(31);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++cnt[__builtin_ctz(x)];
}
while (q--) {
int x;
cin >> x;
int ans = 0;
for (int i = 30; i >= 0 && x > 0; --i) {
int need = min(x >> i, cnt[i]);
ans += need;
x -= (1 << i) * need;
}
if (x > 0)
ans = -1;
cout << ans << 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, d, k;
cin >> n >> d >> k;
if (d >= n) {
cout << "NO" << endl;
return 0;
}
vector<int> deg(n);
vector<pair<int, int>> ans;
set<pair<int, int>> q;
for (int i = 0; i < d; ++i) {
++deg[i];
++deg[i + 1];
if (deg[i] > k || deg[i + 1] > k) {
cout << "NO" << endl;
return 0;
}
ans.push_back(make_pair(i, i + 1));
}
for (int i = 1; i < d; ++i)
q.insert(make_pair(max(i, d - i), i));
for (int i = d + 1; i < n; ++i) {
while (!q.empty() && deg[q.begin()->second] == k)
q.erase(q.begin());
if (q.empty() || q.begin()->first == d) {
cout << "NO" << endl;
return 0;
}
++deg[i];
++deg[q.begin()->second];
ans.push_back(make_pair(i, q.begin()->second));
q.insert(make_pair(q.begin()->first + 1, i));
}
assert(int(ans.size()) == n - 1);
cout << "YES" << endl;
vector<int> p(n);
for (int i = 0; i < n; i++)
p[i] = i;
random_shuffle(p.begin(), p.end());
for (int i = 0; i < n - 1; ++i)
if (rand() % 2)
cout << p[ans[i].first] + 1 << " " << p[ans[i].second] + 1 << endl;
else
cout << p[ans[i].second] + 1 << " " << p[ans[i].first] + 1 << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution (Vovuh)
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
int n;
bool eq[N][N];
int dp[N][N];
string s[N];
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
cin >> n;
int allsum = n - 1;
for (int i = 0; i < n; ++i) {
cin >> s[i];
allsum += s[i].size();
}
for (int i = 0; i < n; ++i) {
eq[i][i] = true;
for (int j = 0; j < i; ++j) {
eq[i][j] = eq[j][i] = s[i] == s[j];
}
}
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (eq[i][j]) {
if (i + 1 < n && j + 1 < n)
dp[i][j] = dp[i + 1][j + 1] + 1;
else
dp[i][j] = 1;
}
}
}
int ans = allsum;
for (int i = 0; i < n; ++i) {
int sum = 0;
for (int j = 0; i + j < n; ++j) {
sum += s[i + j].size();
int cnt = 1;
for (int pos = i + j + 1; pos < n; ++pos) {
if (dp[i][pos] > j) {
++cnt;
pos += j;
}
}
int cur = allsum - sum * cnt + (j + 1) * cnt - j * cnt;
if (cnt > 1 && ans > cur) {
ans = cur;
}
}
}
cout << ans << endl;
return 0;
}