比赛 |
国庆欢乐赛3 |
评测结果 |
AAAAAAATTTTTTTT |
题目名称 |
Following Directions |
最终得分 |
47 |
用户昵称 |
LikableP |
运行时间 |
24.596 s |
代码语言 |
C++ |
内存使用 |
8.17 MiB |
提交时间 |
2025-10-05 09:57:34 |
显示代码纯文本
#include <iostream>
using namespace std;
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
void read(char *str) {
char ch = getchar();
for (; isspace(ch); ch = getchar());
for (; !isspace(ch); ch = getchar()) *str++ = ch;
*str = 0;
}
template <typename T> void write(T x, char ed = '\n') {
int sta[sizeof(T) << 2], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while(x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}
const int MAXN = 1510;
int n, q;
char a[MAXN][MAXN];
int c[MAXN][MAXN];
int callback(int x, int y) {
int res = 0;
if (a[x - 1][y] == 'D') res = res + 1 + callback(x - 1, y);
if (a[x][y - 1] == 'R') res = res + 1 + callback(x, y - 1);
return res;
}
int calcsum() {
int res = 0;
for (int i = 1; i <= n; ++i) {
res += c[i][n + 1] * callback(i, n + 1);
res += c[n + 1][i] * callback(n + 1, i);
}
return res;
}
void change(int x, int y) {
a[x][y] = a[x][y] == 'D' ? 'R' : 'D';
}
int main() {
freopen("zunxun.in", "r", stdin);
freopen("zunxun.out", "w", stdout);
n = read<int>();
for (int i = 1; i <= n; ++i) {
read(a[i] + 1);
c[i][n + 1] = read<int>();
}
for (int i = 1; i <= n; ++i) {
c[n + 1][i] = read<int>();
}
write(calcsum());
cin >> q;
for (int a, b; q--; ) {
a = read<int>(), b = read<int>();
change(a, b);
write(calcsum());
}
return 0;
}