记录编号 607072 评测结果 AAAATTTTTTTTTTT
题目名称 3863.[USACO23 Jan Silver] Following Directions 最终得分 27
用户昵称 GravatarZZ 是否通过 未通过
代码语言 C++ 运行时间 33.083 s
提交时间 2025-10-05 14:47:56 内存使用 6.68 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
 
short n,m[1501][1501],c[1500][1500],q,a,b;
short x,y;
int ans;
char ch;
 
short f(short w,short z){
    if( w==n || z==n ) return m[w][z];
    else if(m[w][z]) return f(w,z+1);
    else return f(w+1,z);
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("zunxun.in","r",stdin);
    freopen("zunxun.out","w",stdout);
    
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>ch;
            if(ch=='R') m[i][j]=1;
        }
        cin>>m[i][n];
    }
    for(int i=0;i<n;i++){
        cin>>m[n][i];
    }
    
    while(x<n){
        while(y<n){
            c[x][y]=f(x,y);
            ans+=c[x][y];
            y++;
        }
        x++;
        y=0;
    }
    cout<<ans<<endl;
    
    cin>>q;
    while(q--){
        ans=0;
        cin>>a>>b;
        a--;
        b--;
        m[a][b]=!m[a][b]; 
        x=0;
        while(x<n){
            while(y<n){
                c[x][y]=f(x,y);
                ans+=c[x][y];
                y++;
            }
            x++;
            y=0;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}