Submission #839878

# Submission time Handle Problem Language Result Execution time Memory
839878 2023-08-30T19:19:09 Z AdamGS Longest Trip (IOI23_longesttrip) C++17
85 / 100
22 ms 360 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
  mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
  vector<int>V, A, B;
  rep(i, n) {
    V.pb(i);
    swap(V[i], V[rng()%(i+1)]);
  }
  A.pb(V[0]);
  for(int i=1; i<n; ++i) {
    if(A.size()<B.size()) swap(A, B);
    if(B.size()==0) {
      B.pb(V[i]);
      continue;
    }
    vector<int>X, Y;
    X.pb(V[i]);
    if(rng()%2) {
      Y.pb(A.back());
      if(are_connected(X, Y)) A.pb(V[i]);
      else {
        Y[0]=B.back();
        if(are_connected(X, Y)) B.pb(V[i]);
        else {
          while(B.size()>0) {
            A.pb(B.back());
            B.pop_back();
          }
          B.pb(V[i]);
        }
      }
    } else {
      Y.pb(B.back());
      if(are_connected(X, Y)) B.pb(V[i]);
      else {
        Y[0]=A.back();
        if(are_connected(X, Y)) A.pb(V[i]);
        else {
          while(B.size()>0) {
            A.pb(B.back());
            B.pop_back();
          }
          B.pb(V[i]);
        }
      }
    }
    if(rng()%2) reverse(all(A));
    if(rng()%2) reverse(all(B));
  }
  if(B.size()>A.size()) swap(A, B);
  if(B.size()==0) return A;
  vector<int>X, Y;
  X.pb(A[0]);
  Y.pb(B[0]);
  if(are_connected(X, Y)) {
    reverse(all(A));
    for(auto i : B) A.pb(i);
    return A;
  }
  Y.clear();
  Y.pb(B.back());
  if(are_connected(X, Y)) {
    for(auto i : A) B.pb(i);
    return B;
  }
  X.clear();
  Y.clear();
  X.pb(A.back());
  Y.pb(B[0]);
  if(are_connected(X, Y)) {
    for(auto i : B) A.pb(i);
    return A;
  }
  if(!are_connected(A, B)) return A;
  int po=0, ko=A.size()-1;
  while(po<ko) {
    int sr=(po+ko)/2;
    vector<int>tmp;
    rep(i, sr+1) tmp.pb(A[i]);
    if(are_connected(tmp, B)) ko=sr; else po=sr+1;
  }
  X.clear();
  X.pb(A[po]);
  int po2=0, ko2=B.size()-1;
  while(po2<ko2) {
    int sr=(po2+ko2)/2;
    vector<int>tmp;
    rep(i, sr+1) tmp.pb(B[i]);
    if(are_connected(X, tmp)) ko2=sr; else po2=sr+1;
  }
  vector<int>ans;
  rep(i, A.size()) ans.pb(A[(i+po+1)%A.size()]);
  rep(i, B.size()) ans.pb(B[(i+po2)%B.size()]);
  return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
longesttrip.cpp:99:3: note: in expansion of macro 'rep'
   99 |   rep(i, A.size()) ans.pb(A[(i+po+1)%A.size()]);
      |   ^~~
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
longesttrip.cpp:100:3: note: in expansion of macro 'rep'
  100 |   rep(i, B.size()) ans.pb(B[(i+po2)%B.size()]);
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 11 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 11 ms 208 KB Output is correct
4 Correct 9 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 17 ms 208 KB Output is correct
8 Correct 11 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 13 ms 208 KB Output is correct
11 Correct 7 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 6 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 11 ms 208 KB Output is correct
4 Correct 7 ms 208 KB Output is correct
5 Correct 13 ms 208 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 11 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 9 ms 208 KB Output is correct
12 Correct 8 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 22 ms 208 KB Output is correct
15 Correct 10 ms 208 KB Output is correct
16 Correct 15 ms 208 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 12 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 13 ms 208 KB Output is correct
21 Correct 11 ms 208 KB Output is correct
22 Correct 11 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 19 ms 208 KB Output is correct
26 Correct 21 ms 236 KB Output is correct
27 Correct 9 ms 208 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 19 ms 208 KB Output is correct
30 Correct 13 ms 256 KB Output is correct
31 Correct 13 ms 208 KB Output is correct
32 Correct 18 ms 208 KB Output is correct
33 Correct 6 ms 228 KB Output is correct
34 Correct 14 ms 208 KB Output is correct
35 Correct 12 ms 300 KB Output is correct
36 Correct 9 ms 256 KB Output is correct
37 Correct 10 ms 208 KB Output is correct
38 Correct 10 ms 208 KB Output is correct
39 Correct 14 ms 208 KB Output is correct
40 Correct 13 ms 208 KB Output is correct
41 Correct 11 ms 208 KB Output is correct
42 Correct 15 ms 256 KB Output is correct
43 Correct 12 ms 208 KB Output is correct
44 Correct 13 ms 256 KB Output is correct
45 Correct 12 ms 212 KB Output is correct
46 Correct 22 ms 208 KB Output is correct
47 Correct 16 ms 216 KB Output is correct
48 Correct 10 ms 208 KB Output is correct
49 Correct 14 ms 256 KB Output is correct
50 Correct 11 ms 208 KB Output is correct
51 Correct 17 ms 344 KB Output is correct
52 Correct 12 ms 208 KB Output is correct
53 Correct 11 ms 208 KB Output is correct
54 Correct 11 ms 208 KB Output is correct
55 Correct 13 ms 308 KB Output is correct
56 Correct 14 ms 208 KB Output is correct
57 Correct 14 ms 288 KB Output is correct
58 Correct 15 ms 288 KB Output is correct
59 Correct 14 ms 304 KB Output is correct
60 Correct 16 ms 304 KB Output is correct
61 Correct 15 ms 308 KB Output is correct
62 Correct 17 ms 288 KB Output is correct
63 Correct 9 ms 288 KB Output is correct
64 Correct 13 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 12 ms 304 KB Output is correct
5 Correct 8 ms 256 KB Output is correct
6 Correct 13 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
8 Correct 11 ms 208 KB Output is correct
9 Correct 11 ms 300 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 9 ms 236 KB Output is correct
12 Correct 10 ms 220 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 12 ms 208 KB Output is correct
15 Correct 10 ms 220 KB Output is correct
16 Correct 14 ms 240 KB Output is correct
17 Correct 8 ms 256 KB Output is correct
18 Correct 12 ms 220 KB Output is correct
19 Correct 11 ms 208 KB Output is correct
20 Correct 6 ms 304 KB Output is correct
21 Correct 14 ms 208 KB Output is correct
22 Correct 12 ms 220 KB Output is correct
23 Correct 9 ms 240 KB Output is correct
24 Correct 8 ms 220 KB Output is correct
25 Correct 13 ms 240 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 15 ms 208 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 10 ms 208 KB Output is correct
31 Correct 15 ms 208 KB Output is correct
32 Correct 10 ms 208 KB Output is correct
33 Correct 16 ms 208 KB Output is correct
34 Correct 7 ms 208 KB Output is correct
35 Correct 8 ms 208 KB Output is correct
36 Correct 14 ms 208 KB Output is correct
37 Correct 10 ms 208 KB Output is correct
38 Correct 15 ms 208 KB Output is correct
39 Correct 18 ms 208 KB Output is correct
40 Correct 14 ms 208 KB Output is correct
41 Correct 10 ms 208 KB Output is correct
42 Correct 8 ms 312 KB Output is correct
43 Correct 11 ms 256 KB Output is correct
44 Correct 11 ms 208 KB Output is correct
45 Correct 9 ms 208 KB Output is correct
46 Correct 7 ms 208 KB Output is correct
47 Correct 7 ms 208 KB Output is correct
48 Correct 15 ms 208 KB Output is correct
49 Partially correct 11 ms 208 KB Output is partially correct
50 Correct 10 ms 208 KB Output is correct
51 Correct 15 ms 220 KB Output is correct
52 Correct 12 ms 208 KB Output is correct
53 Correct 14 ms 208 KB Output is correct
54 Partially correct 11 ms 208 KB Output is partially correct
55 Partially correct 14 ms 208 KB Output is partially correct
56 Correct 13 ms 208 KB Output is correct
57 Correct 10 ms 208 KB Output is correct
58 Correct 9 ms 208 KB Output is correct
59 Correct 10 ms 208 KB Output is correct
60 Correct 13 ms 208 KB Output is correct
61 Correct 14 ms 208 KB Output is correct
62 Correct 8 ms 316 KB Output is correct
63 Partially correct 11 ms 312 KB Output is partially correct
64 Partially correct 16 ms 312 KB Output is partially correct
65 Correct 14 ms 312 KB Output is correct
66 Partially correct 16 ms 308 KB Output is partially correct
67 Partially correct 17 ms 360 KB Output is partially correct
68 Partially correct 7 ms 304 KB Output is partially correct
69 Partially correct 14 ms 208 KB Output is partially correct
70 Partially correct 16 ms 296 KB Output is partially correct
71 Correct 13 ms 208 KB Output is correct
72 Partially correct 14 ms 308 KB Output is partially correct
73 Partially correct 10 ms 208 KB Output is partially correct
74 Partially correct 15 ms 208 KB Output is partially correct
75 Partially correct 15 ms 308 KB Output is partially correct
76 Partially correct 15 ms 208 KB Output is partially correct
77 Correct 11 ms 308 KB Output is correct
78 Partially correct 19 ms 308 KB Output is partially correct
79 Partially correct 11 ms 208 KB Output is partially correct
80 Partially correct 11 ms 208 KB Output is partially correct
81 Partially correct 10 ms 208 KB Output is partially correct
82 Partially correct 10 ms 308 KB Output is partially correct