比赛 |
国庆欢乐赛3 |
评测结果 |
AAAAAAATTTTTTTT |
题目名称 |
Following Directions |
最终得分 |
47 |
用户昵称 |
对立猫猫对立 |
运行时间 |
26.328 s |
代码语言 |
C++ |
内存使用 |
57.63 MiB |
提交时间 |
2025-10-05 10:11:38 |
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
#define For(i, a, b) for(int i = a; i <= b; i++)
using namespace std;
int N, Q;
int rt[1505], dw[1505];
bool vis[1505][1505];
struct ZT {
int a, b;
bool operator==(ZT x) {
return a == x.a && b == x.b;
}
bool operator!=(ZT x) {
return a != x.a || b != x.b;
}
};
int templ[1505][1505], ans;
ZT zt[1505][1505];
void init() {
For(i, 0, 1504) For(j, 0, 1504) zt[i][j] = ZT{i, j};
}
int dfs(int x, int y, int cnt) {
if(x > N || y > N) {
ans += cnt * (x > N ? dw[y] : rt[x]);
return (x > N ? dw[y] : rt[x]);
}
if(templ[x][y]) {
ans += cnt * templ[x][y];
return templ[x][y];
}
else {
templ[x][y] = dfs(zt[x][y].a, zt[x][y].b, cnt + 1);
return templ[x][y];
}
}
void calc() {
memset(vis, false, sizeof vis);
memset(templ, 0, sizeof templ);
ans = 0;
For(i, 1, N) {
For(j, 1, N) {
if (templ[i][j]) continue;
dfs(i, j, 0);
}
}
}
signed main() {
freopen("zunxun.in", "r", stdin);
freopen("zunxun.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N;
init();
For(i, 1, N) {
For(j, 1, N) {
char ch;
cin >> ch;
zt[i][j] = (ch == 'D' ? ZT{i + 1, j} : ZT{i, j + 1});
}
cin >> rt[i];
}
For(i, 1, N) cin >> dw[i];
calc();
cout << ans << '\n';
cin >> Q;
while (Q--) {
int a, b;
cin >> a >> b;
if (zt[a][b] == ZT{a, b + 1}) zt[a][b] = {a + 1, b};
else zt[a][b] = {a, b + 1};
calc();
cout << ans << '\n';
}
return 0;
}