QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469493#6699. Wandering Robotzzisjtu#WA 10ms3772kbC++231.2kb2024-07-09 19:42:582024-07-09 19:42:58

Judging History

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

  • [2024-07-09 19:42:58]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3772kb
  • [2024-07-09 19:42:58]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
pair<ll,ll> maxx(pair<ll,ll>a,pair<ll,ll>b){
    if(labs(a.first)+labs(a.second)>labs(b.first)+labs(b.second))return a;
    return b;
}
void solve()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    pair<ll,ll>a={0,0},b={0,0};
    for(int i=0;i<s.size();i++){
        if(s[i]=='U')a.first+=1;
        else if(s[i]=='D')a.first-=1;
        else if(s[i]=='L')a.second-=1;
        else if(s[i]=='R')a.second+=1;
        b=maxx(a,b);
    }
    ll ans=1ll*labs(b.first)+1ll*labs(b.second);
    if(a!=b)ans+=(1ll*labs(b.first)+1ll*labs(b.second)
        -(labs(a.first)+labs(a.second)))*(k-1);
    else ans=1ll*ans*k;
    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
3 3
RUL
1 1000000000
D

output:

4
1000000000

result:

ok 2 number(s): "4 1000000000"

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3760kb

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:

749263783
122135910
111498848
4825199244
936610227
1338248085
5508341608
581526192
800896919
2490339019
926989474
3762513307
463006533
1581485530
881213211
236693627
816980016
550868458
2
3637885652
2053846776
633993867
684989396
6
749352475
574414669
1580769408
1292925531
1212040569
2073657226
3568...

result:

wrong answer 1st numbers differ - expected: '1873159447', found: '749263783'