Submission #941910

# Submission time Handle Problem Language Result Execution time Memory
941910 2024-03-09T16:40:45 Z benjaminkleyn Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define C are_connected
#define pb push_back
#define bk back
#define rev(x) reverse(all(x))
vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:10:134: error: 'elser' was not declared in this scope
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                      ^~~~~
longesttrip.cpp:10:760: error: 'elseB' was not declared in this scope
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^~~~~
longesttrip.cpp:10:1202: error: 'elsea' was not declared in this scope
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ^~~~~
longesttrip.cpp:10:1335: error: 'elsea' was not declared in this scope
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ^~~~~
longesttrip.cpp:10:1391: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ~~^~~~~~~~~~
longesttrip.cpp:10:1475: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | vi longest_trip(int N, int D){if (D == 3){vi r(N);iota(all(r), 0);return r;}if (D == 2){vi r;int t;if (C({0}, {1}))r = {0, 1}, t = 2;elser = {0, 2, 1}, t = 3;for (int i = t; i < N; i++){if (!C({r.bk()}, {i}))rev(r);r.pb(i);}return r;}vi A = {0}, B = {1};for (int i = 2; i + 1 < N; i += 2){if (C({i}, {i + 1})){if (C({i}, {A.bk(), B.bk()})){if (C({i}, {A.bk()})){A.pb(i);A.pb(i + 1);}else{B.pb(i);B.pb(i + 1);}}else{rev(B);for (int x : B) A.pb(x);B = {i, i + 1};}}else{if (C({A.bk()}, {i})){A.pb(i);if (C({B.bk()}, {i + 1}))B.pb(i + 1);else{rev(B);for (int x : B)A.pb(x);B = {i + 1};}}else{A.pb(i + 1);if (C({B.bk()}, {i}))B.pb(i);else{rev(B);for (int x : B)A.pb(x);B = {i};}}}}if (N % 2){if (C({N - 1}, {A.bk(), B.bk()})){if (C({N - 1}, {A.bk()}))A.pb(N - 1);elseB.pb(N - 1);}else{rev(B);for (int x : B)A.pb(x);B = {N - 1};}}if (!C(A, B)){if (A.size() > B.size())return A;return B;}if (A.size() > 1 && !C({A[0]}, {A.bk()})){if (C({A.bk()}, {B.bk()}))rev(A);for (int x : A)B.pb(x);return B;}if (B.size() > 1 && !C({B[0]}, {B.bk()})){if (C({A.bk()}, {B.bk()}))rev(B);for (int x : B)A.pb(x);return A;}int a = 1, b = A.size();while (a < b){int m = (a + b) / 2;if (C(vi(A.begin(), A.begin() + m), B))b = m;elsea = m + 1;}int x = a - 1;a = 1, b = B.size();while (a < b){int m = (a + b) / 2;if (C(vi(B.begin(), B.begin() + m), {A[x]}))b = m;elsea = m + 1;}int y = a - 1;vi r;for (int i = x + 1; i < A.size(); i++)r.pb(A[i]);for (int i = 0; i <= x; i++)r.pb(A[i]);for (int i = y; i < B.size(); i++)r.pb(B[i]);for (int i = 0; i < y; i++)r.pb(B[i]);return r;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ~~^~~~~~~~~~