Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 2e5 + 10;
void solve()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a[110], b[110];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
for (int i = 1; i <= n; i++)
{
cout << a[i];
if (i != n)
cout << " ";
}
cout << endl;
for (int i = 1; i <= n; i++)
{
cout << b[i];
if (i != n)
cout << " ";
}
cout << endl;
}
}
int main()
{
//freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 2e5 + 10;
string s;
vector<int> ans[1000];
int k;
void solve()
{
cin >> s;
string t = "a";
s = t + s;
int n = s.size() - 1;
for (int i = n / 2; i >= 1; i--)
{
int m = 1000;
while (m--)
{
int cnt1 = 0, l = -1;
for (int j = 1; j <= n; j++)
{
if (s[j] == '(') cnt1++;
if (cnt1 == i) {
l = j;
break;
}
}
int cnt2 = 0, r = -1;
for (int j = n; j >= 1; j--)
{
if (s[j] == ')') cnt2++;
if (cnt2 == i) {
r = j;
break;
}
}
if (r != -1 && l != -1 && r > l)
{
k++;
int cnt1 = 0, cnt2 = 0;
for (int j = 1; j <= n; j++)
{
if (s[j] == '(') s[j] = '.', cnt1++, ans[k].push_back(j);
if (cnt1 == i) break;
}
for (int j = n; j >= 1; j--)
{
if (s[j] == ')') s[j] = '.', cnt2++, ans[k].push_back(j);
if (cnt2 == i) break;
}
}
}
}
cout << k << endl;
for (int i = 1; i <= k; i++)
{
sort(ans[i].begin(), ans[i].end());
cout << ans[i].size() << endl;
for (int j = 0; j < ans[i].size(); j++)
{
cout << ans[i][j];
if (j != ans[i].size() - 1) cout << " ";
}
cout << endl;
}
}
int main()
{
//freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
#pragma GCC optimize(2)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int a[1100];
void solve()
{
int n, m;
cin >> n >> m;
if (n > m) cout << 0;
else
{
for (int i = 1; i <= n; i++)
cin >> a[i];
long long ans = 1;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
ans = ans * abs(a[j] - a[i]) % m;
cout << ans;
}
}
int main()
{
//freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
#pragma GCC optimize(2)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
vector<int> g[1100];
int degree[1100];
void solve()
{
int n;
cin >> n;
for (int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v), g[v].push_back(u);
degree[u]++, degree[v]++;
}
vector<int> a;
for (int i = 1; i <= n; i++)
if (degree[i] == 1) a.push_back(i);
while (a.size() >= 2)
{
int u = a[0], v = a[1];
a.erase(a.begin()), a.erase(a.begin());
cout << "? " << u << " " << v << endl, cout.flush();
int lca; cin >> lca;
if (lca == u || lca == v)
{
cout << "! " << lca, cout.flush();
return;
}
for (auto& it : g[u])
if (--degree[it] == 1) a.push_back(it);
for (auto& it : g[v])
if (--degree[it] == 1) a.push_back(it);
}
cout << "! " << *a.begin(), cout.flush();
}
int main()
{
//freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
#pragma GCC optimize(2)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int ans[6000];
void solve()
{
int n, m, cur = 0, i;
cin >> n >> m;
bool ok = 0;
for (i = 1; i <= n; i++)
{
if (cur + (i - 1) / 2 < m) cur += (i - 1) / 2, ans[i] = i;
else
{
ok = 1;
int p = m - cur;
ans[i] = 2 * i - 2 * p - 1;
if (ans[i] == 0) ans[i]++;
break;
}
}
if (!ok)
{
cout << -1;
return;
}
ans[i + 1] = 100000000;
for (int j = i + 2; j <= n; j++) ans[j] = ans[j - 1] + 6000;
for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}
int main()
{
//freopen("Testin.txt", "r", stdin);
solve();
return 0;
}