답안 #403375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403375 2021-05-13T06:03:30 Z zaneyu 조개 줍기 (KOI17_shell) C++14
0 / 100
482 ms 143448 KB
/*input
3

3 2 7

4 2 6

5 3 8

D 1 2

D 1 1

D 2 2
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
const int maxn=1500+5;
int dp[maxn][maxn];
int arr[maxn][maxn];
int n;
vector<int> v[maxn*maxn];
ll ans=0;
void calc2(){
    REP1(i,n){
        REP1(j,n){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+arr[i][j];
            ans+=dp[i][j];

            if(dp[i][j]==dp[i-1][j]+arr[i][j]){
                //cout<<(i-1)*(n+1)+j<<' '<<i*(n+1)+j<<'\n';
                v[(i-1)*(n+1)+j].pb(i*(n+1)+j);
            }
            if(dp[i][j]==dp[i][j-1]+arr[i][j]){
                v[i*(n+1)+j-1].pb(i*(n+1)+j);
            }
        }
    }
    cout<<ans<<'\n';
}
bool vis[maxn*maxn];
vector<int> vs;
void dfs(int u){
    vis[u]=1;
    vs.pb(u);
    for(int x:v[u]){
        if(!vis[x]){
            int i=x/(n+1),j=x%(n+1);
            int pv=dp[i][j];
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+arr[i][j];
            if(dp[i][j]!=pv){
                dfs(i*(n+1)+j);
            }
            ans+=dp[i][j]-pv;
        }
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    REP1(i,n) REP1(j,n) cin>>arr[i][j];
    calc2();

    REP(i,n){
        char c;
        int x,y;
        cin>>c>>x>>y;
        if(c=='U') arr[x][y]++;
        else arr[x][y]--;
        dp[x][y]--,ans--;
        dfs(x*(n+1)+y);
        for(auto z:vs){
            int i=z/(n+1),j=z%(n+1);
            if(find(ALL(v[i*(n+1)+j-1]),x)!=v[i*(n+1)+j-1].end()) v[i*(n+1)+j-1].erase(find(ALL(v[i*(n+1)+j-1]),x));
            if(find(ALL(v[(i-1)*(n+1)+j]),x)!=v[(i-1)*(n+1)+j].end()) v[(i-1)*(n+1)+j].erase(find(ALL(v[(i-1)*(n+1)+j]),x));
            if(dp[i][j]==dp[i-1][j]+arr[i][j]){
                v[(i-1)*(n+1)+j].pb(x);
            }
            if(dp[i][j]==dp[i][j-1]+arr[i][j]){
                v[i*(n+1)+j-1].pb(x);
            }
            vis[z]=0;
        }
        vs.clear();
        /*REP1(i,(n+1)*(n+1)){
            for(auto x:v[i]) cout<<i<<' '<<x<<'\n';
        }
        REP1(i,n){
            REP1(j,n) cout<<dp[i][j]<<' ';
            cout<<'\n';
        }*/
        cout<<ans<<'\n';
    }
}
/*
107
3 4 11 
7 9 17 
12 15 25 
103
2 3 10 
7 9 16 
12 15 24 
98
2 3 10 
7 8 16 
12 15 24 
97
[Finished in 2.5s]
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 54592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 482 ms 143448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 54592 KB Output isn't correct
2 Halted 0 ms 0 KB -