Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 51;
int n, m;
int a[N][N];
int32_t main()
{
IOS;
int t;
cin >> t;
while(t--)
{
cin >> n >> m;
set r, c;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
if(a[i][j] == 1)
r.insert(i), c.insert(j);
}
}
int mn = min(n — r.size(), m — c.size());
if(mn % 2)
cout << "Ashish" << endl;
else
cout << "Vivek" << endl;
}
return 0;
}
This problem was prepared by Ashishgup
1365B - Проблематичная сортировка
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 1e3 + 5;
int n;
int a[N], b[N];
int32_t main()
{
IOS;
int t;
cin >> t;
while(t--)
{
cin >> n;
bool sorted = 1, have0 = 0, have1 = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
if(i >= 2 && a[i] < a[i - 1])
sorted = 0;
}
for(int i = 1; i <= n; i++)
{
cin >> b[i];
if(!b[i])
have0 = 1;
else
have1 = 1;
}
if(have0 && have1)
cout << "Yes" << endl;
else if(sorted)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
This problem was prepared by Ashishgup
1365C - Соответствия поворотом
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 2e5 + 5;
int n;
int a[N], b[N], pos[N];
map offset;
int32_t main()
{
IOS;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
pos[a[i]] = i;
}
for(int i = 1; i <= n; i++)
cin >> b[i];
for(int i = 1; i <= n; i++)
{
int cur = pos[b[i]] - i;
if(cur < 0)
cur += n;
offset[cur]++;
}
int ans = 0;
for(auto &it:offset)
ans = max(ans, it.second);
cout << ans;
return 0;
}
This problem was prepared by Ashishgup and ridbit10
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 55;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
ll res = 1;
x %= mod;
while (n) {
if (n & 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
ll n, m;
char arr[N][N];
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool valid(ll i, ll j) { return i >= 1 && i <= n && j >= 1 && j <= m; }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--) {
cin >> n >> m;
for (ll i = 1; i <= n; i++) {
cin >> (arr[i] + 1);
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (arr[i][j] == 'B') {
for (ll k = 0; k < 4; k++) {
ll ni = i + dir[k][0];
ll nj = j + dir[k][1];
if (valid(ni, nj) && arr[ni][nj] == '.')
arr[ni][nj] = '#';
}
}
}
}
queue> que;
bool visited[n + 5][m + 5];
memset(visited, false, sizeof(visited));
if (arr[n][m] == '.') {
que.push({n, m});
visited[n][m] = true;
}
while (!que.empty()) {
pair curr = que.front();
que.pop();
for (ll k = 0; k < 4; k++) {
ll ni = curr.first + dir[k][0];
ll nj = curr.second + dir[k][1];
if (valid(ni, nj) && !visited[ni][nj] && arr[ni][nj] != '#') {
que.push({ni, nj});
visited[ni][nj] = true;
}
}
}
bool good = true;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if ((arr[i][j] == 'G' && !visited[i][j]) or
(arr[i][j] == 'B' && visited[i][j])) {
good = false;
break;
}
}
}
cout << (good ? "Yes" : "No") << en;
}
return 0;
}
This problem was prepared by Vivek1998299
1365E - Максимальное значение подпоследовательности
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 505;
int n;
int a[N];
int32_t main()
{
IOS;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
int ans = 0;
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
for(int k = j; k <= n; k++)
ans = max(ans, (a[i] | a[j] | a[k]));
cout << ans;
return 0;
}
This problem was prepared by Ashishgup and ridbit10
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tc;
cin >> tc;
while(tc--){
int n;
cin >> n;
map, int> pairs;
vector a(n), b(n);
bool possible = 1;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n; i++)
cin >> b[i];
for(int i = 0; i < (n + 1) / 2; i++){
pair p = {min(a[i], a[n — 1 — i]), max(a[i], a[n — 1 — i])};
pairs[p]++;
}
for(int i = 0; i < (n + 1) / 2; i++){
pair p = {min(b[i], b[n — 1 — i]), max(b[i], b[n — 1 — i])};
if(pairs[p] <= 0)
possible = 0;
pairs[p]--;
}
if(possible)
cout << "Yes" << endl;
else cout << "No" << endl;
}
}
This problem was prepared by FastestFinger, Ashishgup and Vivek1998299
Tutorial
Tutorial is loading...
Code
#include
using namespace std;
#define ll long long
#define vint vector
const int Q = 13;
ll query(vint v){
cout << "? " << v.size() << ' ';
for(ll i : v)
cout << i + 1 << ' ';
cout << endl;
fflush(stdout);
ll or_value;
cin >> or_value;
return or_value;
}
int main(){
int n;
cin >> n;
vector ask(Q);
vint assign_mask(n);
vector or_value(Q), answer(n);
int assigned = 0;
for(int i = 1; i < (1 << Q); i++){
if(__builtin_popcount(i) != Q / 2)
continue;
assign_mask[assigned] = i;
for(int j = 0; j < Q; j++)
if((i >> j & 1) == 0)
ask[j].push_back(assigned);
assigned++;
if(assigned == n)
break;
}
for(int i = 0; i < Q; i++)
if(!ask[i].empty())
or_value[i] = query(ask[i]);
for(int i = 0; i < n; i++)
for(int j = 0; j < Q; j++)
if(assign_mask[i] >> j & 1)
answer[i] |= or_value[j];
cout << "! ";
for(ll i : answer)
cout << i << ' ';
cout << endl;
}
This problem was prepared by FastestFinger