Codeforces Round #648 (Div. 2)
E题离谱, wa2, 就得了892,难道是水体吗😒
A
直接统计能填的位置就行了
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[51][51];
bool h[51], l[51];
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_)
{
cin >> n >> m;
int x = n, y = m;
memset(h, 0, sizeof h);
memset(l, 0, sizeof l);
rep(i, 1, n)
rep (j, 1, m)
{
cin >> a[i][j];
if (a[i][j] == 0) continue;
if (h[i] == 0) h[i] = 1, --x;
if (l[j] == 0) l[j] = 1, --y;
}
if (min(x, y) & 1) cout << "Ashish\n";
else cout << "Vivek\n";
}
return 0;
}
B
思维水体
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[501], b[501];
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_)
{
cin >> n; bool flag = 1;
rep (i, 1, n)
{
cin >> a[i];
if (a[i] < a[i - 1]) flag = 0;
}
bool x = 0, y = 0;
rep (i, 1, n)
{
cin >> a[i];
if (a[i] & 1) x = 1;
else y = 1;
}
if (flag) cout << "Yes\n";
else if (x && y) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
C
左移右移是相对的, 直接预处理l[i],表示左移i位答案, r[i]右移答案, 排序取最大值
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
int a[N], b[N];
int l[N], r[N];
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
rep (i, 1, n)
{
cin >> a[0];
a[a[0]] = i;
}
rep (i, 1, n)
{
cin >> b[i];
int c = a[b[i]];
if (c <= i) ++l[i - c], ++r[c + n - i];
else ++l[i + n - c], ++r[c - i];
}
sort(l, l + N); sort(r, r + N);
cout << max(l[N - 1], r[N - 1]);
return 0;
}
D
简单的宽搜
直接把坏人围死, 让好人能走出去
注意下细节就行
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
char st[55][55];
bool d[55][55];
int der[4][2] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1} };
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_)
{
cin >> n >> m;
memset(d, 0, sizeof d);
int isg = 0, isb = 0, is = 0;
rep (i, 1, n)
{
cin >> st[i] + 1;
if (is) continue;
rep (j, 1, m)
{
if (st[i][j] == 'B')
{
++isb;
if (st[i - 1][j] == 'G' || st[i][j - 1] == 'G') { is = 1; break; }
d[i - 1][j] = d[i][j - 1] = d[i][j + 1] = d[i + 1][j] = 1;
}
else if (st[i][j] == 'G')
{
if (d[i][j]) { is = 1; break; }
++isg;
}
}
}
if (is) { cout << "No\n"; continue; }
if (isg == 0 && isb == 0) { cout << "Yes\n"; continue; }
if (isg == 0) { cout << "Yes\n"; continue; }
if (d[n][m]) { cout << "No\n"; continue; }
d[n][m] = 1;
queue<PII> q; q.push({n, m});
while (!q.empty())
{
PII p = q.front(); q.pop();
rep (i, 0, 3)
{
int x = p.fi + der[i][0], y = p.se + der[i][1];
if (x < 1 || x > n || y < 1 || y > m) continue;
if (st[x][y] == '#' || d[x][y]) continue;
if (st[x][y] == 'G') --isg;
d[x][y] = 1; q.push({x, y});
}
}
if (isg) cout << "No\n";
else cout << "Yes\n";
}
return 0;
}
E
刚开始想复杂了, 发现 max(1, now - 2) = now - 2时
你在选择一个数 对第 j 位做贡献, 仍然是 max(1, now - 2 + 1) = now - 2 + 1 > cnt[j] + 1, 第 j 位还是没贡献
所以我们要让 max(1, now - 2) = 1, 即 now <=3
所以说白了就是找三个数使得答案最大, 搜索+剪枝(没有)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
typedef unsigned long long ull;
const int N = 2e5 + 5;
int n, m, _, k;
int cnt[61];
VI ve[61], vi[505];
ull ans = 0;
ull dfs(int cnta, ull cur, int h)
{
if (cnta == 3) return cur;
while ((cnt[h] != 0 || ve[h].empty()) && h >= 0) --h;
if (h < 0) return cur;
ull ans = cur;
for (int& k : ve[h])
{
ull res = 0;
for (int j : vi[k])
{
if (cnt[j] == 0) res += (1ull << j);
++cnt[j];
}
ans = max(ans, dfs(cnta + 1, cur + res, h - 1));
for (int j: vi[k]) --cnt[j];
}
return ans;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
rep (i, 1, n)
{
ull a; cin >> a;
for (int w = 0; (1ull << w) <= a; ++w)
if (a & (1ull << w)) ve[w].pb(i), vi[i].pb(w);
}
cout << dfs(0, 0, 60);
return 0;
}

浙公网安备 33010602011771号