Submission #839812

# Submission time Handle Problem Language Result Execution time Memory
839812 2023-08-30T17:03:47 Z AdamGS Longest Trip (IOI23_longesttrip) C++17
15 / 100
13 ms 260 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;
  }
  rep(i, A.size()) rep(j, B.size()) {
    X.clear();
    Y.clear();
    X.pb(A[i]);
    Y.pb(B[i]);
    if(are_connected(X, Y)) {
      vector<int>ans;
      rep(l, A.size()) ans.pb(A[(i+l+1)%A.size()]);
      rep(l, B.size()) ans.pb(B[(j+l)%B.size()]);
      return ans;
    }
  }
  return A;
}

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:53:3: note: in expansion of macro 'rep'
   53 |   rep(i, A.size()) rep(j, B.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:53:20: note: in expansion of macro 'rep'
   53 |   rep(i, A.size()) rep(j, B.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:60:7: note: in expansion of macro 'rep'
   60 |       rep(l, A.size()) ans.pb(A[(i+l+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:61:7: note: in expansion of macro 'rep'
   61 |       rep(l, B.size()) ans.pb(B[(j+l)%B.size()]);
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 6 ms 208 KB Output is correct
4 Correct 6 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 5 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
9 Correct 9 ms 208 KB Output is correct
10 Correct 10 ms 208 KB Output is correct
11 Correct 7 ms 208 KB Output is correct
12 Correct 8 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 9 ms 208 KB Output is correct
3 Correct 7 ms 208 KB Output is correct
4 Correct 7 ms 208 KB Output is correct
5 Correct 9 ms 208 KB Output is correct
6 Correct 13 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
9 Correct 8 ms 256 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 7 ms 208 KB Output is correct
12 Correct 8 ms 208 KB Output is correct
13 Correct 8 ms 260 KB Output is correct
14 Incorrect 1 ms 208 KB Incorrect
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 7 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 10 ms 260 KB Output is correct
8 Correct 8 ms 260 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 10 ms 208 KB Output is correct
11 Correct 7 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 10 ms 208 KB Output is correct
14 Incorrect 0 ms 208 KB Incorrect
15 Halted 0 ms 0 KB -