QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#927989#6699. Wandering RobotPonyHex#AC ✓11ms3968kbC++202.9kb2025-03-07 20:31:172025-03-07 20:31:17

Judging History

This is the latest submission verdict.

  • [2025-03-07 20:31:17]
  • Judged
  • Verdict: AC
  • Time: 11ms
  • Memory: 3968kb
  • [2025-03-07 20:31:17]
  • Submitted

answer

#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
//#define double long double
#define int long long
#define lc u<<1
#define rc u<<1|1
#define endl "\n"
#define X first
#define Y second
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> PII;
const ll N = 2e5 + 50, M = 2e6 + 5;
const ll maxm = 2e18;
const ll mod = 1e9 + 7;

ll dx[] = { -1,0,1,0 };
ll dy[] = { 0,1,0,-1 };

//__builtin_popcount();
//a.erase(unique(a.begin(),a.end()),a.end());//去重,吗
ll exgcd(ll a, ll b, ll& x, ll& y);

inline ll gcd(ll a, ll b) {
    return b > 0 ? gcd(b, a % b) : a;
}

ll ksm(ll a, ll b, ll p) {
    ll base = a;
    ll ans = 1;
    while (b) {
        if (b & 1)ans *= base;
        ans %= p;
        base *= base; base %= p;
        b >>= 1;
    }
    return ans % p;
}




/*

struct cmp {
    bool operator()(node a, node b) {
        return a.w > b.w;//表示小根堆
    }
};*/



//setprecision()与printf()舍入规则相同,都不是四舍五入,如果你要实现四舍五入
//请对ans使用round(),小心别在cf给我碰上袄
//map在cf上比unordered_map快,因为群众里面有人造哈希冲突卡你
//当链接关系以gcd()表示时,我们需要对元素取出质因数来构建连接关系
//double能整数运算一定不要double,即使是加法
//正难则反,罗列操作产生的后果,根号分治,1/2分治
//先处理特殊情况

string str;
ll n, k;

void solve() {
    //猜测ans仅会出现第一次和最后一次
    ll ans = 0;
    cin >> n >> k;
    cin >> str;
    ll x1 = 0, y1 = 0;
    ll x2 = 0, y2 = 0;
    
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'U')y2++;
        else if (str[i] == 'D')y2--;
        else if (str[i] == 'L')x2--;
        else x2++;
    }
    
    x2 *= (k - 1); y2 *= (k - 1);

    ll x = 0, y = 0;

    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'U')y++;
        else if (str[i] == 'D')y--;
        else if (str[i] == 'L')x--;
        else x++;
        ans = max(ans, max(llabs(x + x1) + llabs(y + y1), llabs(x + x2) + llabs(y + y2)));
    }

    cout << ans << endl;
}

/*
4
3
1 1 0
4
2 2 2 2
3
0 1 4
1
1000000000
*/


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


/*PonyHex*/

ll exgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1; y = 0;
        return a;
    }
    ll g = exgcd(b, a % b, x, y);
    ll temp = x;
    x = y;
    y = temp - (a / b) * y;
    return g;
}

/*
ll ksm(ll a, ll b) {
    ll base = a;
    ll ans = 1;
    while (b) {
        if (b & 1)ans *= base;
        base *= base;
        b >>= 1;
    }
    return ans;
}*/
/*
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}*/

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
3 3
RUL
1 1000000000
D

output:

4
1000000000

result:

ok 2 number(s): "4 1000000000"

Test #2:

score: 0
Accepted
time: 11ms
memory: 3968kb

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