#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
ll n, d;
pair<ll, vector<ll>> mx;
vector<int> longest_trip(int N, int D)
{
n=N; d=D;
vector<int> a = {0}, b;
for (int i=1; i<N; i++){
if (are_connected(a, vector<int>{i})){
a.push_back(i);
}else{
b.push_back(i);
}
}
if (a.empty() or b.empty()){
return a.empty()?b:a;
}else if (are_connected(a, b)){
ll l=0, r=a.size();
while (l<r){
vector<int> test;
ll mid = (l+r)/2;
for (ll i=l; i<=mid; i++){
test.push_back(a[i]);
}
if (are_connected(test, b)){
r=mid;
}else l=mid+1;
}
int conA = r;
l=0; r=b.size();
while (l<r){
vector<int> test;
ll mid = (l+r)/2;
for (ll i=l; i<=mid; i++){
test.push_back(b[i]);
}
if (are_connected(test, {conA})){
r=mid;
}else l=mid+1;
}
int conB = r;
vector<int> res;
for (auto ch:a){
if (ch==conA) continue;
res.push_back(ch);
}
res.push_back(conA);
res.push_back(conB);
for (auto ch:b){
if (ch==conB) continue;
res.push_back(ch);
}
return res;
}else{
if (a.size()>b.size()) return a;
else return b;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
6 ms |
604 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
336 KB |
Output is correct |
2 |
Correct |
15 ms |
336 KB |
Output is correct |
3 |
Correct |
18 ms |
336 KB |
Output is correct |
4 |
Correct |
22 ms |
336 KB |
Output is correct |
5 |
Correct |
25 ms |
968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
508 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
20 ms |
336 KB |
Output is correct |
4 |
Correct |
24 ms |
336 KB |
Output is correct |
5 |
Correct |
30 ms |
508 KB |
Output is correct |
6 |
Incorrect |
1 ms |
504 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
21 ms |
336 KB |
Output is correct |
4 |
Correct |
19 ms |
588 KB |
Output is correct |
5 |
Correct |
23 ms |
336 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
18 ms |
336 KB |
Output is correct |
4 |
Correct |
19 ms |
336 KB |
Output is correct |
5 |
Correct |
24 ms |
700 KB |
Output is correct |
6 |
Incorrect |
1 ms |
336 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |