Submission #839814

# Submission time Handle Problem Language Result Execution time Memory
839814 2023-08-30T17:09:12 Z AdamGS Longest Trip (IOI23_longesttrip) C++17
85 / 100
28 ms 336 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) {
  vector<int>A, B;
  A.pb(0);
  for(int i=1; i<n; ++i) {
    vector<int>X, Y;
    X.pb(A.back());
    Y.pb(i);
    if(are_connected(X, Y)) A.pb(i);
    else B.pb(i);
    X.clear();
    Y.clear();
    if(B.size()>0) {
      X.pb(A.back());
      Y.pb(B.back());
      if(are_connected(X, Y)) while(B.size()>0) {
        A.pb(B.back());
        B.pop_back();
      }
    }
  }
  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:71:3: note: in expansion of macro 'rep'
   71 |   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:72:3: note: in expansion of macro 'rep'
   72 |   rep(i, B.size()) ans.pb(B[(i+po2)%B.size()]);
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 3 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 7 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 6 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 7 ms 208 KB Output is correct
5 Correct 7 ms 296 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 11 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
9 Correct 10 ms 208 KB Output is correct
10 Correct 8 ms 300 KB Output is correct
11 Correct 8 ms 300 KB Output is correct
12 Correct 5 ms 208 KB Output is correct
13 Correct 8 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 8 ms 208 KB Output is correct
4 Correct 6 ms 208 KB Output is correct
5 Correct 5 ms 304 KB Output is correct
6 Correct 13 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 9 ms 208 KB Output is correct
11 Correct 10 ms 300 KB Output is correct
12 Correct 11 ms 300 KB Output is correct
13 Correct 10 ms 300 KB Output is correct
14 Correct 26 ms 208 KB Output is correct
15 Correct 21 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 10 ms 208 KB Output is correct
18 Correct 14 ms 208 KB Output is correct
19 Correct 13 ms 208 KB Output is correct
20 Correct 10 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 12 ms 304 KB Output is correct
23 Correct 10 ms 296 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 23 ms 208 KB Output is correct
26 Correct 25 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 14 ms 208 KB Output is correct
29 Correct 14 ms 208 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 11 ms 208 KB Output is correct
32 Correct 19 ms 208 KB Output is correct
33 Correct 17 ms 208 KB Output is correct
34 Correct 12 ms 208 KB Output is correct
35 Correct 17 ms 208 KB Output is correct
36 Correct 11 ms 208 KB Output is correct
37 Correct 16 ms 208 KB Output is correct
38 Correct 14 ms 208 KB Output is correct
39 Correct 19 ms 296 KB Output is correct
40 Correct 19 ms 208 KB Output is correct
41 Correct 15 ms 208 KB Output is correct
42 Correct 11 ms 208 KB Output is correct
43 Correct 18 ms 300 KB Output is correct
44 Correct 12 ms 208 KB Output is correct
45 Correct 14 ms 208 KB Output is correct
46 Correct 9 ms 208 KB Output is correct
47 Correct 12 ms 208 KB Output is correct
48 Correct 15 ms 208 KB Output is correct
49 Correct 11 ms 208 KB Output is correct
50 Correct 10 ms 208 KB Output is correct
51 Correct 15 ms 208 KB Output is correct
52 Correct 11 ms 208 KB Output is correct
53 Correct 14 ms 208 KB Output is correct
54 Correct 13 ms 300 KB Output is correct
55 Correct 21 ms 208 KB Output is correct
56 Correct 12 ms 288 KB Output is correct
57 Correct 12 ms 208 KB Output is correct
58 Correct 10 ms 308 KB Output is correct
59 Correct 20 ms 208 KB Output is correct
60 Correct 19 ms 288 KB Output is correct
61 Correct 18 ms 296 KB Output is correct
62 Correct 14 ms 208 KB Output is correct
63 Correct 17 ms 296 KB Output is correct
64 Correct 16 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 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 7 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 7 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 10 ms 208 KB Output is correct
9 Correct 9 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 6 ms 296 KB Output is correct
12 Correct 8 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 28 ms 208 KB Output is correct
15 Correct 21 ms 208 KB Output is correct
16 Correct 11 ms 208 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 14 ms 208 KB Output is correct
19 Correct 6 ms 256 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 11 ms 208 KB Output is correct
22 Correct 19 ms 208 KB Output is correct
23 Correct 15 ms 208 KB Output is correct
24 Correct 14 ms 208 KB Output is correct
25 Correct 13 ms 208 KB Output is correct
26 Correct 10 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 12 ms 208 KB Output is correct
30 Correct 11 ms 208 KB Output is correct
31 Correct 13 ms 208 KB Output is correct
32 Correct 10 ms 208 KB Output is correct
33 Correct 15 ms 208 KB Output is correct
34 Correct 10 ms 208 KB Output is correct
35 Correct 15 ms 208 KB Output is correct
36 Correct 14 ms 208 KB Output is correct
37 Correct 13 ms 208 KB Output is correct
38 Correct 14 ms 208 KB Output is correct
39 Correct 11 ms 208 KB Output is correct
40 Correct 11 ms 208 KB Output is correct
41 Correct 11 ms 208 KB Output is correct
42 Correct 13 ms 208 KB Output is correct
43 Correct 8 ms 208 KB Output is correct
44 Correct 7 ms 208 KB Output is correct
45 Correct 12 ms 300 KB Output is correct
46 Correct 12 ms 208 KB Output is correct
47 Partially correct 14 ms 304 KB Output is partially correct
48 Partially correct 18 ms 208 KB Output is partially correct
49 Partially correct 11 ms 296 KB Output is partially correct
50 Partially correct 18 ms 296 KB Output is partially correct
51 Partially correct 18 ms 208 KB Output is partially correct
52 Partially correct 11 ms 208 KB Output is partially correct
53 Partially correct 18 ms 208 KB Output is partially correct
54 Partially correct 18 ms 296 KB Output is partially correct
55 Partially correct 13 ms 208 KB Output is partially correct
56 Partially correct 11 ms 208 KB Output is partially correct
57 Partially correct 17 ms 208 KB Output is partially correct
58 Partially correct 17 ms 208 KB Output is partially correct
59 Partially correct 9 ms 336 KB Output is partially correct
60 Partially correct 14 ms 300 KB Output is partially correct
61 Partially correct 19 ms 208 KB Output is partially correct
62 Correct 13 ms 208 KB Output is correct
63 Partially correct 13 ms 300 KB Output is partially correct
64 Partially correct 15 ms 312 KB Output is partially correct
65 Partially correct 18 ms 304 KB Output is partially correct
66 Partially correct 18 ms 208 KB Output is partially correct
67 Partially correct 13 ms 208 KB Output is partially correct
68 Partially correct 15 ms 208 KB Output is partially correct
69 Partially correct 10 ms 308 KB Output is partially correct
70 Partially correct 15 ms 208 KB Output is partially correct
71 Partially correct 12 ms 208 KB Output is partially correct
72 Partially correct 14 ms 208 KB Output is partially correct
73 Partially correct 13 ms 304 KB Output is partially correct
74 Partially correct 17 ms 296 KB Output is partially correct
75 Partially correct 15 ms 208 KB Output is partially correct
76 Partially correct 16 ms 208 KB Output is partially correct
77 Partially correct 12 ms 304 KB Output is partially correct
78 Partially correct 14 ms 300 KB Output is partially correct
79 Partially correct 19 ms 304 KB Output is partially correct
80 Partially correct 19 ms 300 KB Output is partially correct
81 Partially correct 19 ms 208 KB Output is partially correct
82 Partially correct 19 ms 296 KB Output is partially correct