比赛 |
4043级2023省选模拟赛6 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
Following Directions |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.866 s |
代码语言 |
C++ |
内存使用 |
13.44 MiB |
提交时间 |
2023-03-28 09:20:38 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=1500+5;
int n,m;
char s[N][N];
ll c[N<<1],f[N][N],ans=0;
void change(int x,int y,ll w){
f[x][y]+=w;
if (x==n+1){
ans+=w*c[y+n];return ;
}
if (y==n+1){
ans+=w*c[x];return ;
}
if (s[x][y]=='D')change(x+1,y,w);
else change(x,y+1,w);
}
int main(){
freopen ("zunxun.in","r",stdin);
freopen ("zunxun.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%s",s[i]+1);scanf("%lld",&c[i]);
}
for (int i=1;i<=n;i++)scanf("%lld",&c[i+n]);
for (int i=1;i<=n+1;i++){
for (int j=1;j<=n+1;j++){
if (s[i-1][j]=='D')f[i][j]+=f[i-1][j];
if (s[i][j-1]=='R')f[i][j]+=f[i][j-1];
if (i<=n&&j<=n)f[i][j]++;
}
}
for (int i=1;i<=n;i++)ans+=f[i][n+1]*c[i]+f[n+1][i]*c[i+n];
printf("%lld\n",ans);
scanf("%d",&m);
for (int i=1;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
if (s[x][y]=='D'){
change(x+1,y,-f[x][y]);
s[x][y]='R';
change(x,y+1,f[x][y]);
}
else{
change(x,y+1,-f[x][y]);
s[x][y]='D';
change(x+1,y,f[x][y]);
}
printf("%lld\n",ans);
}
}