This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 30000;
vector<int> chienSurTour[NMAX];
int puissanceChien[NMAX];
bool trouveTour[NMAX];
struct T {
int tour = 0, chien = 0;
T(int a, int b)
{
tour = a;
chien = b;
}
};
bool dejaVu[NMAX][NMAX];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int nbTours, nbChiens;
cin >> nbTours >> nbChiens;
int pos0;
for(int i = 0; i < nbChiens; i++)
{
int deb, p;
cin >> deb >> p;
puissanceChien[i] = p;
if(i == 0)
{
pos0 = deb;
}
chienSurTour[deb].push_back(i);
}
vector<T> caseMaint;
vector<T> proCase;
proCase.push_back(T(pos0, 0));
int distance = -1;
while(proCase.size())
{
distance++;
caseMaint = proCase;
proCase.clear();
for(auto cas : caseMaint)
{
if(cas.tour >= nbTours) continue;
if(cas.tour < 0) continue;
if(dejaVu[cas.tour][cas.chien]) continue;
dejaVu[cas.tour][cas.chien] = true;
proCase.push_back(T(cas.tour - puissanceChien[cas.chien], cas.chien));
proCase.push_back(T(cas.tour + puissanceChien[cas.chien], cas.chien));
if(!trouveTour[cas.tour])
{
trouveTour[cas.tour] = true;
for(int c : chienSurTour[cas.tour])
{
if(c == 1)
{
cout << distance;
return 0;
}
proCase.push_back(T(cas.tour - puissanceChien[c], c));
proCase.push_back(T(cas.tour + puissanceChien[c], c));
}
}
}
}
cout << -1;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:11:14: warning: 'pos0' may be used uninitialized in this function [-Wmaybe-uninitialized]
11 | tour = a;
| ~~~~~^~~
skyscraper.cpp:22:9: note: 'pos0' was declared here
22 | int pos0;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |