I'm currently a HS student! I'm participating in the Woburn Challenge here in Canada in about a week. I was trying the past contest problems, and this specific problem is throwing me off. My program works partially.
In 14/27 solutions, I output the correct answers, but for the rest, there must be some mistake I'm not catching. I came here because I've tried everything I know, and also could not understand the official solution provided by the website.
If anyone could take time to understand the problem and analyze what I've done wrong, that would be spectacular. It's a fun problem so you could think it is a challenge!
The link to the problem: https://wcipeg.com/problem/wc181s3
test input/output data: https://drive.google.com/file/d/1oOBqs9gSbt2i7qByUxEuB0_lRWSduBZm/view
You can find the official solutions here: https://static1.squarespace.com/static/5602365be4b02ead4f1620e0/t/5bef52d3758d46849662051e/1542410963506/wc-2018-19-round1-solutions.pdf
Thanks so much!
Here is my interpretation and try; the language I use is C++:
#include <iostream>
using namespace std;
int main() {
int height, reach, badSections;
cin >> height >> reach >> badSections;
int height1, height2;
string rope[height+reach];
for(int h = 0; h < height+reach; h++)
rope[h] = "safe";
for(int b = 0; b < badSections; b++)
{
cin >> height1 >> height2;
for(int h = height1; h <= height2; h++)
{
rope[h] = "itchy";
if(h == reach)
{
cout << "-1";
return 0;
}
}
if(height2-height1+1 >= reach)
{
cout << "-1";
return 0;
}
}
int currPos = 0;
int drop = 0;
int moveCount = 0;
//for(int r = 0; r < 5; r++)
while(currPos < height)
{
if(rope[currPos+reach] == "safe")
{
currPos += reach;
moveCount++;
}
else
{
drop = 0;
while(rope[currPos-drop] == "itchy" || rope[currPos+reach-drop] == "itchy")
{
drop++;
if(drop >= reach)
{
cout << "-1";
return 0;
}
}
currPos -= drop;
moveCount++;
}
}
cout << moveCount;
}
Aucun commentaire:
Enregistrer un commentaire