#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef pair<int,int> ii;
const int mxN = 1505;
int N, A[mxN][mxN], B[mxN][mxN], up[mxN][mxN];
long long S;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N;
FOR(i,1,N){
FOR(j,1,N){
cin >> A[i][j];
B[i][j] = max(B[i-1][j], B[i][j-1]) + A[i][j];
S += B[i][j];
}
}
cout << S << '\n';
FOR(i,1,N){
char op;
int r, c, v;
cin >> op >> r >> c;
v = (op == 'U' ? 1 : -1);
queue<ii> q;
A[r][c] += v;
B[r][c] += v;
S += v;
q.push(ii(r,c));
while (!q.empty()) {
auto u = q.front(); q.pop();
int dr[] = {0,1};
int dc[] = {1,0};
FOR(k,0,1){
int nr = u.first + dr[k], nc = u.second + dc[k];
if (nr <= N && nc <= N &&
max(B[nr-1][nc], B[nr][nc-1]) + A[nr][nc] != B[nr][nc]) {
B[nr][nc] += v;
S += v;
q.push(ii(nr,nc));
}
}
}
cout << S << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
3 ms |
1100 KB |
Output is correct |
3 |
Correct |
6 ms |
1100 KB |
Output is correct |
4 |
Correct |
15 ms |
1200 KB |
Output is correct |
5 |
Correct |
14 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1200 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
3 ms |
1100 KB |
Output is correct |
9 |
Correct |
3 ms |
1100 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
17964 KB |
Output is correct |
2 |
Correct |
185 ms |
17932 KB |
Output is correct |
3 |
Correct |
513 ms |
18008 KB |
Output is correct |
4 |
Correct |
158 ms |
17896 KB |
Output is correct |
5 |
Correct |
161 ms |
17964 KB |
Output is correct |
6 |
Correct |
211 ms |
18144 KB |
Output is correct |
7 |
Correct |
182 ms |
17988 KB |
Output is correct |
8 |
Correct |
162 ms |
17968 KB |
Output is correct |
9 |
Correct |
174 ms |
18060 KB |
Output is correct |
10 |
Correct |
163 ms |
17968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
3 ms |
1100 KB |
Output is correct |
3 |
Correct |
6 ms |
1100 KB |
Output is correct |
4 |
Correct |
15 ms |
1200 KB |
Output is correct |
5 |
Correct |
14 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1200 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
3 ms |
1100 KB |
Output is correct |
9 |
Correct |
3 ms |
1100 KB |
Output is correct |
10 |
Correct |
186 ms |
17964 KB |
Output is correct |
11 |
Correct |
185 ms |
17932 KB |
Output is correct |
12 |
Correct |
513 ms |
18008 KB |
Output is correct |
13 |
Correct |
158 ms |
17896 KB |
Output is correct |
14 |
Correct |
161 ms |
17964 KB |
Output is correct |
15 |
Correct |
211 ms |
18144 KB |
Output is correct |
16 |
Correct |
182 ms |
17988 KB |
Output is correct |
17 |
Correct |
162 ms |
17968 KB |
Output is correct |
18 |
Correct |
174 ms |
18060 KB |
Output is correct |
19 |
Correct |
163 ms |
17968 KB |
Output is correct |
20 |
Correct |
2 ms |
1100 KB |
Output is correct |
21 |
Correct |
245 ms |
17968 KB |
Output is correct |
22 |
Correct |
263 ms |
26588 KB |
Output is correct |
23 |
Correct |
253 ms |
26480 KB |
Output is correct |
24 |
Execution timed out |
2059 ms |
26608 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |