# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403382 |
2021-05-13T06:13:14 Z |
zaneyu |
None (KOI17_shell) |
C++14 |
|
1942 ms |
152148 KB |
/*input
3
1 0 0
1 1 0
0 0 0
D 1 1
D 2 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];
int vs[maxn*maxn];
int ptr=0;
inline void dfs(int u){
vis[u]=1;
vs[ptr++]=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(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);
REP(asd,ptr){
int z=vs[asd];
int i=z/(n+1),j=z%(n+1);
if(find(ALL(v[i*(n+1)+j-1]),z)!=v[i*(n+1)+j-1].end()) v[i*(n+1)+j-1].erase(find(ALL(v[i*(n+1)+j-1]),z));
if(find(ALL(v[(i-1)*(n+1)+j]),z)!=v[(i-1)*(n+1)+j].end()) v[(i-1)*(n+1)+j].erase(find(ALL(v[(i-1)*(n+1)+j]),z));
if(dp[i][j]==dp[i-1][j]+arr[i][j]){
v[(i-1)*(n+1)+j].pb(z);
}
if(dp[i][j]==dp[i][j-1]+arr[i][j]){
v[i*(n+1)+j-1].pb(z);
}
vis[z]=0;
}
ptr=0;
/*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]
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
54556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
141948 KB |
Output is correct |
2 |
Correct |
602 ms |
142008 KB |
Output is correct |
3 |
Correct |
1942 ms |
152148 KB |
Output is correct |
4 |
Correct |
439 ms |
146500 KB |
Output is correct |
5 |
Correct |
467 ms |
146244 KB |
Output is correct |
6 |
Correct |
688 ms |
146536 KB |
Output is correct |
7 |
Correct |
594 ms |
146464 KB |
Output is correct |
8 |
Correct |
435 ms |
146264 KB |
Output is correct |
9 |
Correct |
463 ms |
146364 KB |
Output is correct |
10 |
Correct |
435 ms |
146256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
54556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |