ABC 203 E - White Pawn
E - White Pawn
DP
设 表示 是否能到达
初始化
-
若 是白子,则 的值为 这一列的上一个黑子的值
-
若 是黑子,则
所以将 黑子按 从小到大排序,不断更新 即可
但若两个黑子在同一行且相邻,它们的只应该与这一行之前最近的 的黑子的值有关
但按上述转移则求完一个黑子后, 被更新了,那下一个黑子用到的 值已经被覆盖了
所以可以对于每一行的 , 先把他们的答案放到 中,这一行都更新完了再给 赋值
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, m;
map<int, vector<int> > mp;
map<int, bool> st;
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
mp[x].push_back(y);
}
for (auto [i, vt] : mp)
sort(vt.begin(), vt.end());
st[n] = true;
for (auto [i, vt] : mp)
{
map<int, bool> tmp;
for (auto y : vt)
tmp[y] = st[y-1] | st[y+1];
for (auto [y, s] : tmp)
st[y] = tmp[y];
}
int ans = 0;
for (auto [y, s] : st)
ans += s;
cout << ans << endl;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构