QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339330 | #7866. Teleportation | Rifal | WA | 0ms | 6956kb | C++17 | 1.6kb | 2024-02-27 02:57:30 | 2024-02-27 02:57:30 |
Judging History
answer
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
const int N = 1e5 + 5;
vector<pair<int,bool>> v[N];
pair<int,bool> dis[N];
int x;
void bfs(int s) {
for(int i = 0; i < N; i++) dis[i].first = INF;
dis[s] = {0,0};
queue<int> q;
q.push(s);
while(!q.empty()) {
int cur = q.front();
q.pop();
for(auto i : v[cur]) {
//cout << cur << ' ' << i.first << 'd' << endl;
if(dis[cur].second == 0 && i.second == 1) continue;
if((dis[i.first].first > dis[cur].first+1)) {
dis[i.first].first = dis[cur].first+1;
dis[i.first].second = 1;
q.push(i.first);
}
else if(dis[x].first == INF) {
dis[i.first].first = dis[cur].first+1;
dis[i.first].second = 1;
q.push(i.first);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n; cin >> n >> x; int arr[n];
for(int i = 0; i < n; i++) {
int y; cin >> y;
v[i].push_back({(i+y)%n,0});
v[i].push_back({(i+1)%n,1});
}
bfs(0); cout << dis[x].first << endl;
//for(int i = 0; i < n; i++) cout << i << ' ' << dis[i].first << ' ' << dis[i].second << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6956kb
input:
4 3 0 1 2 3
output:
6
result:
wrong answer 1st numbers differ - expected: '4', found: '6'