QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288751#7866. Teleportationucup-team133#WA 0ms3796kbC++231.6kb2023-12-23 13:20:422023-12-23 13:20:43

Judging History

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

  • [2023-12-23 13:20:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2023-12-23 13:20:42]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    cin >> a;

    vector<int> dp(n + 1, INF);
    queue<int> que;
    dp[n] = 0;
    que.emplace(n);
    while (not que.empty()) {
        int v = que.front();
        que.pop();
        int val = dp[v];
        if (v != n and chmin(dp[(v + 1) % n], val + 1)) que.emplace((v + 1) % n);
        int nxt = v < n ? a[v] : a[0];
        if (chmin(dp[nxt], val + 1)) que.emplace(nxt);
    }

    int ans = dp[x];
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3484kb

input:

300 25
182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...

output:

6

result:

wrong answer 1st numbers differ - expected: '10', found: '6'