QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182718 | #6699. Wandering Robot | ucup-team004 | AC ✓ | 10ms | 4296kb | C++20 | 1.0kb | 2023-09-18 14:30:08 | 2023-09-18 14:30:08 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, k;
std::cin >> n >> k;
i64 ans = 0;
std::string s;
std::cin >> s;
std::vector<int> fx(n + 1), fy(n + 1);
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
x--;
} else if (s[i] == 'R') {
x++;
} else if (s[i] == 'D') {
y--;
} else {
y++;
}
fx[i + 1] = x;
fy[i + 1] = y;
}
for (int i = 0; i <= n; i++) {
ans = std::max(ans, 1LL * std::abs(fx[i]) + std::abs(fy[i]));
i64 x = 1LL * fx[n] * (k - 1) + fx[i];
i64 y = 1LL * fy[n] * (k - 1) + fy[i];
ans = std::max(ans, std::abs(x) + std::abs(y));
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
2 3 3 RUL 1 1000000000 D
output:
4 1000000000
result:
ok 2 number(s): "4 1000000000"
Test #2:
score: 0
Accepted
time: 10ms
memory: 4296kb
input:
10307 33 374631889 RUDUUDLDDUULULDRDDRRRRDDDLRURULDL 9 40711970 UUDLRDRDD 3 111498848 LRL 14 804199874 LRRLLRULRUURUU 44 936610223 ULDRUULRRDLRRLRLRLRDUDDUDDUUDDLRUUDRUURLULUD 15 669124042 RUULRLDDULUDRDR 47 500758328 LRULULLLLUDURLRRDLDDLUUDURUDDLLLLDRLULURDULRDLU 18 581526184 DLLUDUUULUDULULRLR 47...
output:
1873159447 122135910 111498848 4825199244 3746440893 669124044 5508341608 4652209473 5606278385 8301130033 3707957881 2821884978 463006533 1581485530 881213211 236693627 816980016 4406947601 1057578188 1455154265 4107693543 5705944723 3424946932 1154164548 4496114815 3733695266 6323077602 2262619671...
result:
ok 10307 numbers