// incorrect/sol_na_D1_wa.cpp
#include "longesttrip.h"
#include <deque>
#include <functional>
#include <algorithm>
#include <iostream>
std::vector<int> longest_trip(int N, int D)
{
std::deque<int> A = {0}, B;
for (int i = 1; i < N; ++i)
{
if (are_connected({A.back()}, {i}))
{
A.push_back(i);
}
else if (B.empty() || are_connected({B.back()}, {i}))
{
B.push_back(i);
}
else
{
while (!B.empty())
{
A.push_back(B.back());
B.pop_back();
}
B = {i};
}
}
if (A.size() > B.size())
A.swap(B);
std::function<std::vector<int>(std::deque<int>, std::deque<int>)> solve;
solve = [&](std::deque<int> A, std::deque<int> B) -> std::vector<int>
{
if (A.size() > B.size())
A.swap(B);
if (B.size() == N)
return std::vector<int>(B.begin(), B.end());
bool x = are_connected({A.back()}, {B.front()});
bool y = are_connected({A.back()}, {B.back()});
if (x)
{
while (!A.empty())
{
B.push_front(A.back());
A.pop_back();
}
return std::vector<int>(B.begin(), B.end());
}
else if (0 && y)
{ //<<<---
while (!A.empty())
{
B.push_back(A.back());
A.pop_back();
}
return std::vector<int>(B.begin(), B.end());
}
else
{
if (are_connected(std::vector<int>(A.begin(), A.end()), std::vector<int>(B.begin(), B.end())))
{
int L = 0, R = A.size() - 1;
auto BB = std::vector<int>(B.begin(), B.end());
while (L < R)
{
int mid = (L + R) / 2;
if (are_connected(std::vector<int>(A.begin(), A.begin() + mid + 1), BB))
{
R = mid;
}
else
{
L = mid + 1;
}
}
int firstA = L;
L = 0;
R = B.size() - 1;
auto AA = std::vector<int>(A.begin(), A.begin() + firstA + 1);
while (L < R)
{
int mid = (L + R) / 2;
if (are_connected(AA, std::vector<int>(B.begin(), B.begin() + mid + 1)))
{
R = mid;
}
else
{
L = mid + 1;
}
}
int firstB = L;
while (firstB > 0)
{
B.push_back(B.front());
B.pop_front();
firstB--;
}
std::deque<int> lst;
if (firstA >= (int)A.size() / 2)
{
while (firstA >= 0)
{
lst.push_back(A.front());
A.pop_front();
firstA--;
}
}
else
{
while (firstA < (int)A.size())
{
lst.push_front(A.back());
A.pop_back();
}
reverse(lst.begin(), lst.end());
}
while (!lst.empty())
{
B.push_front(lst.back());
lst.pop_back();
}
return solve(A, B);
}
else
{
return std::vector<int>(B.begin(), B.end());
}
}
};
return solve(A, B);
}
Compilation message
longesttrip.cpp: In lambda function:
longesttrip.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (B.size() == N)
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
208 KB |
Output is correct |
3 |
Correct |
10 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
8 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
5 ms |
288 KB |
Output is correct |
6 |
Correct |
10 ms |
300 KB |
Output is correct |
7 |
Correct |
10 ms |
208 KB |
Output is correct |
8 |
Correct |
10 ms |
208 KB |
Output is correct |
9 |
Correct |
7 ms |
296 KB |
Output is correct |
10 |
Correct |
8 ms |
208 KB |
Output is correct |
11 |
Correct |
8 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
11 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
296 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
300 KB |
Output is correct |
5 |
Correct |
12 ms |
208 KB |
Output is correct |
6 |
Correct |
14 ms |
208 KB |
Output is correct |
7 |
Correct |
7 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
208 KB |
Output is correct |
10 |
Correct |
9 ms |
300 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
7 ms |
208 KB |
Output is correct |
13 |
Correct |
9 ms |
208 KB |
Output is correct |
14 |
Correct |
16 ms |
208 KB |
Output is correct |
15 |
Correct |
10 ms |
208 KB |
Output is correct |
16 |
Incorrect |
7 ms |
208 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
296 KB |
Output is correct |
4 |
Correct |
5 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
10 ms |
300 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
9 ms |
208 KB |
Output is correct |
11 |
Correct |
9 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
208 KB |
Output is correct |
13 |
Correct |
10 ms |
208 KB |
Output is correct |
14 |
Correct |
14 ms |
208 KB |
Output is correct |
15 |
Correct |
8 ms |
252 KB |
Output is correct |
16 |
Incorrect |
3 ms |
296 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |