#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
int n,a[1505][1505];
ll dp[1505][1505];
bool vis[1505][1505];
ll s=0;
char t;
int r,c;
queue<ii> q;
int main(){
sf("%d",&n);
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
sf("%d",&a[i][j]);
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
dp[i][j]=a[i][j]+max(dp[i-1][j],dp[i][j-1]);
s+=dp[i][j];
}
}
pf("%lld\n",s);
for(int i=0;i<n;++i){
sf(" %c",&t);
sf("%d%d",&r,&c);
if(t=='U')++a[r][c];
else --a[r][c];
q.push(ii(r,c));
vis[r][c]=true;
while(!q.empty()){
int x,y;tie(x,y)=q.front();q.pop();
vis[x][y]=false;
ll pv=dp[x][y];
s-=dp[x][y];
dp[x][y]=a[x][y]+max(dp[x-1][y],dp[x][y-1]);
s+=dp[x][y];
if(pv!=dp[x][y]){
if(x!=n&&!vis[x+1][y]){
q.push(ii(x+1,y));
vis[x+1][y]=true;
}
if(y!=n&&!vis[x][y+1]){
q.push(ii(x,y+1));
vis[x][y+1]=true;
}
}
}
printf("%lld\n",s);
}
}
Compilation message
shell.cpp: In function 'int main()':
shell.cpp:50:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | sf("%d",&n);
| ^
shell.cpp:53:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | sf("%d",&a[i][j]);
| ^
shell.cpp:64:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | sf(" %c",&t);
| ^
shell.cpp:65:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | sf("%d%d",&r,&c);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1356 KB |
Output is correct |
2 |
Correct |
3 ms |
1332 KB |
Output is correct |
3 |
Correct |
7 ms |
1356 KB |
Output is correct |
4 |
Correct |
18 ms |
1420 KB |
Output is correct |
5 |
Correct |
16 ms |
1336 KB |
Output is correct |
6 |
Correct |
18 ms |
1424 KB |
Output is correct |
7 |
Correct |
4 ms |
1332 KB |
Output is correct |
8 |
Correct |
4 ms |
1356 KB |
Output is correct |
9 |
Correct |
4 ms |
1356 KB |
Output is correct |
10 |
Correct |
3 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
250 ms |
28340 KB |
Output is correct |
2 |
Correct |
276 ms |
28200 KB |
Output is correct |
3 |
Correct |
717 ms |
29844 KB |
Output is correct |
4 |
Correct |
241 ms |
27816 KB |
Output is correct |
5 |
Correct |
220 ms |
27992 KB |
Output is correct |
6 |
Correct |
260 ms |
28228 KB |
Output is correct |
7 |
Correct |
241 ms |
28196 KB |
Output is correct |
8 |
Correct |
242 ms |
28008 KB |
Output is correct |
9 |
Correct |
212 ms |
27812 KB |
Output is correct |
10 |
Correct |
212 ms |
27912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1356 KB |
Output is correct |
2 |
Correct |
3 ms |
1332 KB |
Output is correct |
3 |
Correct |
7 ms |
1356 KB |
Output is correct |
4 |
Correct |
18 ms |
1420 KB |
Output is correct |
5 |
Correct |
16 ms |
1336 KB |
Output is correct |
6 |
Correct |
18 ms |
1424 KB |
Output is correct |
7 |
Correct |
4 ms |
1332 KB |
Output is correct |
8 |
Correct |
4 ms |
1356 KB |
Output is correct |
9 |
Correct |
4 ms |
1356 KB |
Output is correct |
10 |
Correct |
250 ms |
28340 KB |
Output is correct |
11 |
Correct |
276 ms |
28200 KB |
Output is correct |
12 |
Correct |
717 ms |
29844 KB |
Output is correct |
13 |
Correct |
241 ms |
27816 KB |
Output is correct |
14 |
Correct |
220 ms |
27992 KB |
Output is correct |
15 |
Correct |
260 ms |
28228 KB |
Output is correct |
16 |
Correct |
241 ms |
28196 KB |
Output is correct |
17 |
Correct |
242 ms |
28008 KB |
Output is correct |
18 |
Correct |
212 ms |
27812 KB |
Output is correct |
19 |
Correct |
212 ms |
27912 KB |
Output is correct |
20 |
Correct |
3 ms |
1356 KB |
Output is correct |
21 |
Correct |
261 ms |
29684 KB |
Output is correct |
22 |
Correct |
319 ms |
31056 KB |
Output is correct |
23 |
Correct |
303 ms |
30984 KB |
Output is correct |
24 |
Execution timed out |
2056 ms |
31000 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |