Submission #847049

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
8470492023-09-09 03:39:13math_rabbit_1028Longest Trip (IOI23_longesttrip)C++17
100 / 100
15 ms604 KiB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
int find_connected(vector<int> v, vector<int> arr) {
int s = 0, e = arr.size() - 1;
while (s < e) {
int m = (s + e) / 2;
vector<int> temp;
for (int i = s; i <= m; i++) temp.push_back(arr[i]);
if (are_connected(v, temp)) e = m;
else s = m + 1;
}
return s;
}
vector<int> longest_trip(int N, int D) {
int n = N;
vector<int> res;
int ch[256]; for (int i = 0; i < n; i++) ch[i] = 0;
vector<int> p1, p2;
p1.push_back(0);
if (are_connected({0}, {1})) p1.push_back(1);
else p2.push_back(1);
for (int i = 2; i < n; i += 2) {
if (!are_connected({p1.back()}, {i})) swap(p1, p2);
p1.push_back(i);
if (i == n - 1) continue;
if (are_connected({i}, {i + 1})) {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:54:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 for (int i = b + 1; i < p1.size(); i++) res.push_back(p1[i]);
      |                                     ~~^~~~~~~~~~~
longesttrip.cpp:56:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |                 for (int i = a; i < p2.size(); i++) res.push_back(p2[i]);
      |                                 ~~^~~~~~~~~~~
longesttrip.cpp:63:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int i = 0; i < p1.size(); i++) res.push_back(p1[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:64:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             for (int i = 0; i < p2.size(); i++) res.push_back(p2[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:70:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for (int i = 0; i < p1.size(); i++) res.push_back(p1[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int i = 0; i < p2.size(); i++) res.push_back(p2[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:75:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             for (int i = 0; i < p1.size(); i++) res.push_back(p1[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for (int i = 0; i < p2.size(); i++) res.push_back(p2[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:81:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for (int i = 0; i < p1.size(); i++) res.push_back(p1[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:82:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             for (int i = 0; i < p2.size(); i++) res.push_back(p2[i]);
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:21:9: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
   21 |     int ch[256]; for (int i = 0; i < n; i++) ch[i] = 0;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...