mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-12 02:50:01 +00:00
feat: 实现P8865题目的C和F格式计算功能
添加完整的解题代码,包括输入处理、动态规划计算和结果输出。主要功能包括: - 读取输入数据并初始化地图 - 计算每个位置的右侧和下侧可达范围 - 根据题目要求计算C和F格式的结果 - 输出最终计算结果
This commit is contained in:
parent
a59dc23b13
commit
b7d76322ab
@ -1,6 +0,0 @@
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
}
|
102
src/9/7/P8865.cpp
Normal file
102
src/9/7/P8865.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using ll = int64_t;
|
||||
const ll mod = 998244353;
|
||||
|
||||
#define p(v)do{\
|
||||
std::cout<<#v<<":\n";\
|
||||
for(ll i=1;i<=n;i++){\
|
||||
for(ll j=1;j<=m;j++){\
|
||||
std::cout<<(v)[i][j]<<' ';\
|
||||
}\
|
||||
std::cout<<"\n";\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
ll t,id;
|
||||
std::cin>>t>>id;
|
||||
while(t--){
|
||||
ll n,m,c,f;
|
||||
std::cin>>n>>m>>c>>f;
|
||||
static std::vector<std::vector<bool>> map;
|
||||
map.clear();
|
||||
map.resize(n+1,std::vector<bool>(m+1));
|
||||
for(ll i=1;i<=n;i++){
|
||||
static std::string s;
|
||||
std::cin>>s;
|
||||
ll idx=1;
|
||||
for(char c:s){
|
||||
map[i][idx++]=c-'0';
|
||||
}
|
||||
}
|
||||
|
||||
static std::vector<std::vector<ll>> rt;
|
||||
rt.clear();
|
||||
rt.resize(n+1,std::vector<ll>(m+2));
|
||||
for(ll i=1;i<=n;i++){
|
||||
for(ll j=m;j>=1;j--){
|
||||
if(map[i][j]==0){
|
||||
rt[i][j]=(rt[i][j+1]+1)%mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
// p(rt);
|
||||
static std::vector<std::vector<ll>> d;
|
||||
d.clear();
|
||||
d.resize(n+2,std::vector<ll>(m+1));
|
||||
for(ll j=1;j<=m;j++){
|
||||
for(ll i=n;i>=1;i--){
|
||||
if(map[i][j]==0){
|
||||
d[i][j]=(d[i+1][j]+1)%mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
// p(d);
|
||||
ll ansc=0,ansf=0;
|
||||
static std::vector<std::vector<ll>> visc,visf;
|
||||
visc.clear();visc.resize(n+1,std::vector<ll>(m+1));
|
||||
visf.clear();visf.resize(n+1,std::vector<ll>(m+1));
|
||||
for(ll i=1;i<=n-2;i++){
|
||||
for(ll j=1;j<=m;j++){
|
||||
if(rt[i][j]<=1 || rt[i+1][j]==0 || rt[i+2][j]==0){
|
||||
continue;
|
||||
}
|
||||
ll top = rt[i][j]-1;
|
||||
// ll nansc = 0;
|
||||
// ll nansf = 0;
|
||||
ll bc=ansc,bf=ansf;
|
||||
for(ll k=i+2;k<=n;k++){
|
||||
if(rt[k][j]==0)break;
|
||||
if(rt[k][j]>1){
|
||||
// if(visc[i][j]){
|
||||
// ansc=(ansc+visc[i][j])%mod;
|
||||
// }else{
|
||||
ansc=(ansc+top*(rt[k][j]-1)%mod)%mod;
|
||||
visc[i][j]=((ansc-bc)%mod+mod)%mod;
|
||||
// }
|
||||
// if(visf[i][j]){
|
||||
// ansf=(ansf+visf[i][j])%mod;
|
||||
// }else{
|
||||
ansf=(ansf+top*(rt[k][j]-1)%mod*(d[k][j]-1)%mod)%mod;
|
||||
visf[i][j]=((ansf-bf)%mod+mod)%mod;
|
||||
// }
|
||||
// printf("C format i=%lld, j=%lld, k=%lld, nowc=%lld\n"
|
||||
// ,i,j,k, ansc+=top*(rt[k][j]-1));
|
||||
// printf("F format i=%lld, j=%lld, k=%lld, nowf=%lld\n"
|
||||
// ,i,j,k, ansf+= top*(rt[k][j]-1)*(d[k][j]-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout<<ansc*c%mod<<" "<<ansf*f%mod<<"\n";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user