Submission #1071994

# Submission time Handle Problem Language Result Execution time Memory
1071994 2024-08-23T13:09:34 Z Mihailo Longest Trip (IOI23_longesttrip) C++17
85 / 100
17 ms 608 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pll pair<long long, long long>
#define MOD 1000000007ll
#define xx first
#define yy second
using namespace std;
typedef long long ll;
mt19937 mt(169);

bool are_connected(vector<int> A, vector<int> B);

vector<int> sh;
int cnt=0;

bool query(vector<int> a, vector<int> b) {
    cnt++;
    if(a.empty()||b.empty()) while (true);
    vector<int> A, B;
    for(int i=0; i<a.size(); i++) A.pb(sh[a[i]]);
    for(int i=0; i<b.size(); i++) B.pb(sh[b[i]]);
    /*for(int i:a) cout<<i<<' ';
    cout<<'\n';
    for(int i:b) cout<<i<<' ';
    cout<<'\n';*/
    return are_connected(A, B);
}

int cur, zadnji, sled, bound=500;
bool nema;
vector<int> put, klika;

int ko(int jedan, vector<int> vise, int l, int r) {
    if(l==r) return l;
    vector<int> a, b;
    a.pb(jedan);
    int m=(l+r)/2;
    for(int i=l; i<=m; i++) b.pb(vise[i]);
    if(query(a, b)) return ko(jedan, vise, l, m);
    else return ko(jedan, vise, m+1, r);
}

int komnogo(vector<int> jedan, vector<int> vise, int l, int r) {
    if(l==r) return l;
    vector<int> a, b;
    a=jedan;
    int m=(l+r)/2;
    for(int i=l; i<=m; i++) b.pb(vise[i]);
    if(query(a, b)) return komnogo(jedan, vise, l, m);
    else return komnogo(jedan, vise, m+1, r);
}

vector<int> vrati(vector<int> v) {
    vector<int> rez;
    for(int i:v) rez.pb(sh[i]);
    return rez;
}

vector<int> longest_trip(int N, int D) {
    cnt=0;
    sh.clear();
    for(int i=0; i<N; i++) sh.pb(i);
    shuffle(sh.begin(), sh.end(), mt);
    //for(int i=0; i<N; i++) cout<<sh[i]<<' ';
    //cout<<'\n';
    cur=0;
    zadnji=0;
    klika.clear();
    put.clear();
    put.pb(0);
    vector<int> a, b;
    while(zadnji<N-1) {
        if(zadnji<cur) while (true);
        a.clear();
        b.clear();
        if(klika.empty()) {
            a.pb(cur);
            b.pb(zadnji+1);
            if(query(a, b)) {
                cur=zadnji+1;
                put.pb(cur);
                zadnji=max(cur, zadnji);
                continue;
            }
            klika.pb(zadnji+1);
            zadnji=max(zadnji, klika.back());
            nema=true;
        }
        else {
            //cout<<cur<<' '<<zadnji<<' '<<klika.back()<<' '<<nema<<'\n';
            sled=zadnji+1;
            if(nema) {
                a.pb(cur);
                b.pb(sled);
                if(query(a, b)) {
                    cur=sled;
                    put.pb(cur);
                    zadnji=max(cur, zadnji);
                    nema=false;
                }
                else {
                    klika.pb(sled);
                    zadnji=max(klika.back(), zadnji);
                }
                continue;
            }
            bool test;
            a.pb(cur);
            klika.pb(sled);
            test=query(a, klika);
            klika.pop_back();
            if(test) {
                if(query(a, klika)) {
                    sled=klika[ko(cur, klika, 0, klika.size()-1)];
                    put.pb(sled);
                    for(int i:klika) {
                        if(i!=sled) {
                            put.pb(i);
                            cur=i;
                        }
                    }
                    if(klika.size()==1) cur=sled;
                    klika.clear();
                    continue;
                }
                nema=false;
                cur=sled;
                put.pb(cur);
                zadnji=max(cur, zadnji);
                continue;
            }
            else {
                nema=true;
                klika.pb(sled);
                zadnji=max(zadnji, klika.back());
            }
        }
    }
    if((!put.empty())&&(!klika.empty())&&query(put, klika)) {
        a.clear();
        b.clear();
        a.pb(put[0]);
        if(query(a, klika)) {
            sled=klika[ko(put[0], klika, 0, klika.size()-1)];
            reverse(put.begin(), put.end());
            put.pb(sled);
            for(int i:klika) if(i!=sled) put.pb(i);
            if(cnt>bound) while(true);
            return vrati(put);
        }
        a.clear();
        a.pb(put.back());
        if(query(a, klika)) {
            sled=klika[ko(put.back(), klika, 0, klika.size()-1)];
            put.pb(sled);
            for(int i:klika) if(i!=sled) put.pb(i);
            if(cnt>bound) while(true);
            return vrati(put);
        }
        cur=put[komnogo(klika, put, 0, put.size())];
        sled=klika[ko(cur, klika, 0, klika.size()-1)];
        nema=false;
        for(int i:put) {
            if(nema) b.pb(i);
            if(i==cur) nema=true;
        }
        for(int i:put) {
            b.pb(i);
            if(i==cur) break;
        }
        b.pb(sled);
        for(int i:klika) if(i!=sled) b.pb(i);
        return vrati(b);
    }
    else {
        if(cnt>bound) while(true);
        if(put.size()>klika.size()) return vrati(put);
        else return vrati(klika);
    }
}













Compilation message

longesttrip.cpp: In function 'bool query(std::vector<int>, std::vector<int>)':
longesttrip.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0; i<a.size(); i++) A.pb(sh[a[i]]);
      |                  ~^~~~~~~~~
longesttrip.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0; i<b.size(); i++) B.pb(sh[b[i]]);
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 440 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 7 ms 380 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 7 ms 344 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 416 KB Output is correct
13 Correct 8 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 8 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 8 ms 444 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 8 ms 440 KB Output is correct
25 Correct 7 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 7 ms 436 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 8 ms 344 KB Output is correct
33 Correct 7 ms 344 KB Output is correct
34 Correct 16 ms 344 KB Output is correct
35 Correct 8 ms 444 KB Output is correct
36 Correct 6 ms 344 KB Output is correct
37 Correct 17 ms 600 KB Output is correct
38 Correct 9 ms 344 KB Output is correct
39 Correct 9 ms 344 KB Output is correct
40 Correct 9 ms 344 KB Output is correct
41 Correct 9 ms 344 KB Output is correct
42 Correct 11 ms 344 KB Output is correct
43 Correct 8 ms 344 KB Output is correct
44 Correct 9 ms 596 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 8 ms 344 KB Output is correct
48 Correct 7 ms 340 KB Output is correct
49 Correct 9 ms 344 KB Output is correct
50 Correct 7 ms 344 KB Output is correct
51 Correct 8 ms 344 KB Output is correct
52 Correct 8 ms 344 KB Output is correct
53 Correct 12 ms 444 KB Output is correct
54 Correct 10 ms 344 KB Output is correct
55 Correct 8 ms 344 KB Output is correct
56 Correct 6 ms 344 KB Output is correct
57 Correct 8 ms 344 KB Output is correct
58 Correct 10 ms 448 KB Output is correct
59 Correct 15 ms 344 KB Output is correct
60 Correct 9 ms 344 KB Output is correct
61 Correct 8 ms 344 KB Output is correct
62 Correct 13 ms 344 KB Output is correct
63 Correct 9 ms 344 KB Output is correct
64 Correct 12 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 8 ms 344 KB Output is correct
5 Correct 8 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 7 ms 440 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 11 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 13 ms 344 KB Output is correct
21 Correct 10 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 12 ms 344 KB Output is correct
28 Correct 11 ms 344 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 12 ms 344 KB Output is correct
31 Correct 8 ms 440 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 12 ms 344 KB Output is correct
34 Correct 12 ms 344 KB Output is correct
35 Correct 11 ms 344 KB Output is correct
36 Correct 12 ms 344 KB Output is correct
37 Correct 10 ms 600 KB Output is correct
38 Correct 10 ms 344 KB Output is correct
39 Correct 8 ms 344 KB Output is correct
40 Correct 10 ms 600 KB Output is correct
41 Correct 12 ms 448 KB Output is correct
42 Correct 9 ms 600 KB Output is correct
43 Correct 7 ms 344 KB Output is correct
44 Correct 6 ms 344 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 8 ms 440 KB Output is correct
47 Partially correct 8 ms 444 KB Output is partially correct
48 Partially correct 13 ms 344 KB Output is partially correct
49 Partially correct 7 ms 344 KB Output is partially correct
50 Correct 14 ms 468 KB Output is correct
51 Correct 14 ms 344 KB Output is correct
52 Correct 12 ms 344 KB Output is correct
53 Correct 13 ms 344 KB Output is correct
54 Correct 15 ms 448 KB Output is correct
55 Correct 8 ms 344 KB Output is correct
56 Partially correct 12 ms 344 KB Output is partially correct
57 Partially correct 10 ms 344 KB Output is partially correct
58 Correct 11 ms 468 KB Output is correct
59 Correct 11 ms 344 KB Output is correct
60 Correct 11 ms 596 KB Output is correct
61 Correct 11 ms 452 KB Output is correct
62 Correct 7 ms 600 KB Output is correct
63 Partially correct 9 ms 464 KB Output is partially correct
64 Partially correct 16 ms 448 KB Output is partially correct
65 Correct 13 ms 600 KB Output is correct
66 Correct 10 ms 600 KB Output is correct
67 Correct 11 ms 600 KB Output is correct
68 Correct 15 ms 452 KB Output is correct
69 Correct 14 ms 600 KB Output is correct
70 Correct 10 ms 344 KB Output is correct
71 Partially correct 9 ms 344 KB Output is partially correct
72 Partially correct 11 ms 344 KB Output is partially correct
73 Correct 11 ms 600 KB Output is correct
74 Correct 13 ms 444 KB Output is correct
75 Correct 14 ms 344 KB Output is correct
76 Correct 13 ms 608 KB Output is correct
77 Partially correct 11 ms 448 KB Output is partially correct
78 Partially correct 12 ms 344 KB Output is partially correct
79 Correct 15 ms 444 KB Output is correct
80 Correct 13 ms 468 KB Output is correct
81 Correct 11 ms 476 KB Output is correct
82 Correct 12 ms 456 KB Output is correct