P7910 76pts (TLE)

This commit is contained in:
2024-10-10 21:15:37 +08:00
parent 783cd3980a
commit 64e55d4c4b
4 changed files with 52 additions and 8 deletions

View File

@@ -4,7 +4,7 @@
using namespace std;
//#define ENABLE_LOG
#define ENABLE_LOG
struct snake {
int id;
@@ -29,8 +29,8 @@ bool sort_by_id(snake a, snake b) {
return b.id > a.id;
}
void eat(vector<snake> &vec, bool skip_sort = false) {
if (vec.size() < 2) return;
bool eat(vector<snake> &vec, bool skip_sort = false, int initial_id = 0) {
if (vec.size() < 2) return true;
if (!skip_sort) {
sort(vec.begin(), vec.end());
}
@@ -42,8 +42,8 @@ void eat(vector<snake> &vec, bool skip_sort = false) {
}
#endif
if (!(vec[0] >= vec[vec.size() - 1])) {
return;
if (!(vec[initial_id] >= vec[vec.size() - 1])) {
return true;
}
// If this snake ate the last snake
@@ -53,7 +53,7 @@ void eat(vector<snake> &vec, bool skip_sort = false) {
printf("%d gonna to eat %d\n", curr.id, last.id);
#endif
vec.pop_back();
vec[0].power -= last.power;
vec[initial_id].power -= last.power;
sort(vec.begin(), vec.end());
if (vec[0].id != curr.id) {
bool will_be_eaten = false;
@@ -86,7 +86,6 @@ void eat(vector<snake> &vec, bool skip_sort = false) {
}
}
vec.push_back(last);
return;
}
}