# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403368 |
2021-05-13T05:52:19 Z |
zaneyu |
None (KOI17_shell) |
C++14 |
|
427 ms |
141640 KB |
/*input
3
3 2 7
4 2 6
5 3 8
D 1 2
D 3 2
D 1 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]){
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);
}
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);
}
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) vis[z]=0;
vs.clear();
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
54560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
427 ms |
141640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
54560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |