Автор задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int &e : v) {
cin >> e;
}
vector<int> a = v;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if (v[i] != a[1]) {
cout << i + 1 << "\n";
}
}
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
return 0;
}
Автор задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
int main() {
int t;
cin >> t;
forn(tt, t) {
int n;
cin >> n;
vector<string> f(n);
vector<pair<int,int>> p;
forn(i, n) {
cin >> f[i];
forn(j, n)
if (f[i][j] == '*')
p.push_back({i, j});
}
p.push_back(p[0]);
p.push_back(p[1]);
if (p[0].first == p[1].first) {
p[2].first = (p[2].first + 1) % n;
p[3].first = (p[3].first + 1) % n;
} else if (p[0].second == p[1].second) {
p[2].second = (p[2].second + 1) % n;
p[3].second = (p[3].second + 1) % n;
} else
swap(p[2].first, p[3].first);
f[p[2].first][p[2].second] = '*';
f[p[3].first][p[3].second] = '*';
forn(i, n)
cout << f[i] << endl;
}
}
Автор задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
void no() {
cout << "-1" << endl;
}
void solve() {
int a, b;
cin >> a >> b;
string s;
cin >> s;
for (int times = 0; times < 2; times++) {
for (int i = 0; i < (int) s.size(); i++) {
int j = (int) s.size() - i - 1;
if (s[i] != '?') {
if (s[j] == '?') {
s[j] = s[i];
} else if (s[i] != s[j]) {
no();
return;
}
}
}
reverse(s.begin(), s.end());
}
a -= count(s.begin(), s.end(), '0');
b -= count(s.begin(), s.end(), '1');
int ques = count(s.begin(), s.end(), '?');
bool emptyMid = (s.size() % 2 == 1 && s[s.size() / 2] == '?');
if (a < 0 || b < 0 || a + b != ques || (emptyMid && a % 2 == 0 && b % 2 == 0)) {
no();
return;
}
if (a % 2 == 1 || b % 2 == 1) {
int i = s.size() / 2;
if (s[i] != '?') {
no();
return;
}
s[i] = (a % 2 == 1 ? '0' : '1');
if (a % 2 == 1) {
a--;
} else {
b--;
}
}
if (a % 2 == 1 || b % 2 == 1) {
no();
return;
}
for (int i = 0; i < (int) s.size(); i++) {
if (s[i] == '?') {
int j = s.size() - i - 1;
if (a > 0) {
a -= 2;
s[i] = s[j] = '0';
} else {
b -= 2;
s[i] = s[j] = '1';
}
}
}
cout << s << endl;
}
int main() {
int tests;
cin >> tests;
while (tests-- > 0) {
solve();
}
return 0;
}
Автор задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
void no() {
cout << "-1" << endl;
}
void solve() {
int n;
cin >> n;
vector<int> b(n + 2);
for (int &x : b) {
cin >> x;
}
multiset<int> have(b.begin(), b.end());
long long sum = accumulate(b.begin(), b.end(), 0LL);
for (int x : b) {
have.erase(have.find(x));
sum -= x;
if (sum % 2 == 0 && sum <= 2'000'000'000 && have.find(sum / 2) != have.end()) {
have.erase(have.find(sum / 2));
for (int y : have) {
cout << y << " ";
}
cout << endl;
return;
}
sum += x;
have.insert(x);
}
no();
}
int main() {
int tests;
cin >> tests;
while (tests-- > 0) {
solve();
}
return 0;
}
Авторы задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, l, r, s;
cin >> n >> l >> r >> s;
l--; r--;
for (int first = 1; first + (r - l) <= n; first++) {
int sum = 0;
for (int i = l; i <= r; i++) {
sum += first + (i - l);
}
if (sum <= s && s - sum <= r - l + 1) {
int needAdd = r - (s - sum) + 1;
vector<int> ans(n);
set<int> non_blocked;
for (int i = 1; i <= n; i++) {
non_blocked.insert(i);
}
for (int i = l; i <= r; i++) {
ans[i] = first + (i - l);
if (i >= needAdd) {
ans[i]++;
}
non_blocked.erase(ans[i]);
}
if (ans[r] > n) {
continue;
}
non_blocked.erase(ans[r]);
for (int i = 0; i < l; i++) {
ans[i] = *non_blocked.begin();
non_blocked.erase(non_blocked.begin());
}
for (int i = r + 1; i < n; i++) {
ans[i] = *non_blocked.begin();
non_blocked.erase(non_blocked.begin());
}
for (int i : ans) {
cout << i << " ";
}
cout << "\n";
return;
}
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
while (n--) {
solve();
}
}
Автор задачи: sodafago
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n, c;
cin >> n >> c;
vector<int> a(n);
vector<int> b(n - 1);
for (int &e : a) {
cin >> e;
}
for (int &e : b) {
cin >> e;
}
b.push_back(0);
ll ans = 1e18;
ll cur = 0;
ll bal = 0;
for (int i = 0; i < n; i++) {
ans = min(ans, cur + max(0ll, c - bal + a[i] - 1) / a[i]);
ll newDays = max(0ll, b[i] - bal + a[i] - 1) / a[i];
cur += newDays + 1;
bal += a[i] * newDays - b[i];
}
cout << ans << "\n";
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
return 0;
}
Авторы задачи: MikeMirzayanov
Разбор
Tutorial is loading...
Решение
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e7 + 100;
long long s[N];
int d[N];
int ans[N];
int main() {
fill(d, d + N, -1);
d[1] = 1;
for (int i = 2; i * i < N; i++) {
if (d[i] == -1) {
d[i] = i;
for (int j = i * i; j < N; j += i) {
if (d[j] == -1) {
d[j] = i;
}
}
}
}
s[1] = 1;
for (int i = 2; i < N; i++) {
if (d[i] == -1) {
d[i] = i;
s[i] = i + 1;
} else {
int j = i;
s[i] = 1;
while (j % d[i] == 0) {
j /= d[i];
s[i] = s[i] * d[i] + 1;
}
s[i] *= s[j];
}
}
fill(ans, ans + N, -1);
for (int i = N - 1; i > 0; i--) {
if (s[i] < N) {
ans[s[i]] = i;
}
}
int tests;
cin >> tests;
while (tests-- > 0) {
int c;
cin >> c;
cout << ans[c] << endl;
}
return 0;
}