QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225958#6699. Wandering RobotYcfhnndAC ✓12ms3876kbC++17945b2023-10-25 13:10:442023-10-25 13:10:46

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 13:10:46]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:3876kb
  • [2023-10-25 13:10:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

void solve() {
    i64 n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    i64 x = 0, y = 0;
    for (auto c : s){
        if (c == 'U'){
            y ++;
        }else if (c == 'D'){
            y --;
        }else if (c == 'L'){
            x --;
        }else{
            x ++;
        }
    }
    i64 ans = 0;
    i64 a = 0, b = 0;
    for (auto c : s){
        if (c == 'U'){
            b ++;
        }else if (c == 'D'){
            b --;
        }else if (c == 'L'){
            a --;
        }else{
            a ++;
        }
        ans = max({ans, abs(a) + abs(b), abs((k - 1) * x + a) + abs((k - 1) * y + b)});
    }  
    cout << ans << "\n";

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

input:

2
3 3
RUL
1 1000000000
D

output:

4
1000000000

result:

ok 2 number(s): "4 1000000000"

Test #2:

score: 0
Accepted
time: 12ms
memory: 3804kb

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