Submission #910234

# Submission time Handle Problem Language Result Execution time Memory
910234 2024-01-18T02:32:17 Z biank Longest Trip (IOI23_longesttrip) C++17
30 / 100
8 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define SIZE(x) (int)x.size()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define pb push_back
typedef vector<int> vi;
bool are_connected(vi A, vi B);

vi longest_trip(int N, int D) {
    (void)D;
    queue<vi> q;
    vi P;
    forn(i,N) P.pb(i);
    srand(time(0));
    random_shuffle(ALL(P));
    forn(i,N) q.push({P[i]});
    
    vi a={P[0]}, b;
    
    forsn(i,1,N) {
        if(are_connected({a.back()},{P[i]})) {
            a.pb(P[i]);
        } else if(b.empty() || are_connected({b.back()},{P[i]})) {
            b.pb(P[i]);
        } else {
            reverse(ALL(b));
            forn(j,SIZE(b)) a.pb(b[j]);
            b={P[i]};
        }
    }
    
    if(SIZE(b)>SIZE(a)) swap(a,b);
    return a;
    /*if(b.empty() || !are_connected(a,b)) return a;
    
    vi qa = {a.front()};
    if(a.back() != qa.back()) qa.pb(a.back());
    vi qb = {b.front()};
    if(b.back() != qb.back()) qb.pb(b.back());
    
    if(are_connected(qa, qb)) {
        if(are_connected({a.back()}, {b.front()})) {
            forn(i,SIZE(b)) a.pb(b[i]);
            return a;
        }
        
        if(are_connected({b.back()}, {a.front()})) {
            forn(i,SIZE(a)) b.pb(a[i]);
            return b;
        }
        
        if(are_connected({a.front()},{b.front()})) {
            reverse(ALL(a));
            forn(i,SIZE(b)) a.pb(b[i]);
            return a;
        }
        
        if(are_connected({a.back()}, {b.back()})) {
            reverse(ALL(b));
            forn(i,SIZE(b)) a.pb(b[i]);
            return a;
        }
        
    }
    
    int l=0, r=SIZE(a)-1;
    while(l<r) {
        int m=(l+r)/2;
        if(are_connected(b,vi(a.begin()+l,a.begin()+m+1))) r=m;
        else l=m+1;
    }
    
    int i=l;
    
    l=0, r=SIZE(b)-1;
    while(l<r) {
        int m=(l+r)/2;
        if(are_connected({a[i]},vi(b.begin()+l,b.begin()+m+1))) r=m;
        else l=m+1;
    }
    
    int j=l;
    
    vi ans;
    forsn(p,j+1,SIZE(b)) ans.pb(b[p]);
    forn(p,j+1) ans.pb(b[p]);
    forsn(p,i,SIZE(a)) ans.pb(a[p]);
    forn(p,i) ans.pb(a[p]);
    
    return ans;*/
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 596 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 5 ms 596 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 5 ms 344 KB Output is correct
35 Correct 5 ms 344 KB Output is correct
36 Correct 4 ms 344 KB Output is correct
37 Correct 5 ms 344 KB Output is correct
38 Correct 7 ms 600 KB Output is correct
39 Correct 6 ms 600 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 6 ms 600 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 6 ms 344 KB Output is correct
47 Correct 5 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Correct 5 ms 344 KB Output is correct
50 Correct 4 ms 344 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 7 ms 344 KB Output is correct
53 Correct 5 ms 344 KB Output is correct
54 Correct 5 ms 344 KB Output is correct
55 Correct 5 ms 344 KB Output is correct
56 Correct 4 ms 344 KB Output is correct
57 Correct 7 ms 600 KB Output is correct
58 Correct 5 ms 344 KB Output is correct
59 Correct 6 ms 452 KB Output is correct
60 Correct 6 ms 592 KB Output is correct
61 Correct 8 ms 604 KB Output is correct
62 Correct 7 ms 600 KB Output is correct
63 Correct 6 ms 344 KB Output is correct
64 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -