# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403380 |
2021-05-13T06:11:09 Z |
zaneyu |
None (KOI17_shell) |
C++14 |
|
2000 ms |
164920 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];
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(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){
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;
}
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]
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
54724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
690 ms |
142080 KB |
Output is correct |
2 |
Correct |
646 ms |
146560 KB |
Output is correct |
3 |
Execution timed out |
2088 ms |
164920 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
54724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |