QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#523741#7866. Teleportationwifi32767WA 1ms3764kbC++201.3kb2024-08-18 17:19:362024-08-18 17:19:37

Judging History

This is the latest submission verdict.

  • [2024-08-18 17:19:37]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3764kb
  • [2024-08-18 17:19:36]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = array<ll, 2>;
const int MAX = 1e5 + 10;
const ll mod = 1e9 + 7;
const double eps = 1e-6;

int n, x;
int a[MAX];
bool vis[MAX];
vector<int> graph[MAX];
void solve(){
    cin >> n >> x;
    for (int i = 0; i < n; i ++){
        cin >> a[i];
        if (a[i]) graph[i].push_back((i + a[i]) % n);
        graph[i].push_back((i + 1) % n);
    }
    if (x == 0){
        cout << 0 << endl;
        return;
    }
    int ans = 1;
    queue<int> que;
    que.push(a[0]);
    while (not que.empty()){
        int k = que.size();
        ans ++;
        for (int i = 0; i < k; i ++){
            int u = que.front();
            que.pop();
            for (int v : graph[u]){
                if (vis[v]) continue;
                if (v == x){
                    cout << ans << endl;
                    return;
                }
                que.push(v);
                vis[v] = 1;
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// cout << fixed << setprecision(10);
    // init();
    // int _;cin>>_;while (_ --)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
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: 3648kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3764kb

input:

2 1
1 1

output:

3

result:

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