QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692190#6699. Wandering RobotKdlyh#WA 14ms3808kbC++202.7kb2024-10-31 14:01:332024-10-31 14:01:35

Judging History

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

  • [2024-10-31 14:01:35]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3808kb
  • [2024-10-31 14:01:33]
  • 提交

answer

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef LOCAL
template <class T, size_t size = std::tuple_size<T>::value>
std::string to_debug(T, std::string s = "")
    requires(not std::ranges::range<T>);
std::string to_debug(auto x)
    requires requires(std::ostream& os) { os << x; }
{
    return static_cast<std::ostringstream>(std::ostringstream() << x).str();
}
std::string to_debug(std::ranges::range auto x, std::string s = "")
    requires(not std::is_same_v<decltype(x), std::string>)
{
    for (auto xi : x) {
        s += ", " + to_debug(xi);
    }
    return "[" + s.substr(s.empty() ? 0 : 2) + "]";
}
template <class T, size_t size>
std::string to_debug(T x, std::string s)
    requires(not std::ranges::range<T>)
{
    [&]<size_t... I>(std::index_sequence<I...>) { ((s += ", " + to_debug(get<I>(x))), ...); }(std::make_index_sequence<size>());
    return "(" + s.substr(s.empty() ? 0 : 2) + ")";
}
#define debug(...) std::cerr << __LINE__ << ": (" #__VA_ARGS__ ") = " << to_debug(std::tuple(__VA_ARGS__)) << "\n"
#else
#define debug(x...)
#endif

using i64 = long long;
#define int long long

void solve()
{
#define tests
    int n, nk; std::cin >> n >> nk;
    std::string str; std::cin >> str;
    int dtx {}, dty {};

	auto chmax = [&](auto& a, auto b) {a = a > b ? a : b;};

	int ans{};

    for (int i = 0; i < n; i++) {
        if (str[i] == 'U') {
            dtx -= 1;
        } else if (str[i] == 'D') {
            dtx += 1;
        } else if (str[i] == 'L') {
            dty -= 1;
        } else if (str[i] == 'R') {
            dty += 1;
        }
		// chmax(ans, std::abs(dtx) + std::abs(dty));
    }
    int lstx {dtx * (nk - 1)};
	int lsty {dty * (nk - 1)};
	chmax(ans, std::abs(lstx) + std::abs(lsty));
	for(int i = 0 ; i < n ; i++){
		if (str[i] == 'U') {
            lstx -= 1;
        } else if (str[i] == 'D') {
            lstx += 1;
        } else if (str[i] == 'L') {
            lsty -= 1;
        } else if (str[i] == 'R') {
            lsty += 1;
        }
		chmax(ans, std::abs(lstx) + std::abs(lsty));
	}

	std::cout << ans << "\n";
}

signed main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int _ { 1 };
#ifdef tests
    std::cin >> _;
#endif
    while (_--)
        solve();
    return 0;
}

详细

Test #1:

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

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: 14ms
memory: 3664kb

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:

wrong answer 10306th numbers differ - expected: '49990', found: '25018'