Submission #1007030

#TimeUsernameProblemLanguageResultExecution timeMemory
1007030AmrLongest Trip (IOI23_longesttrip)C++17
15 / 100
11 ms440 KiB
#include "longesttrip.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define F first #define S second #define siz size() #define all(x) (x).begin(), (x).end() std::vector<int> longest_trip(int N, int D) { if(N==3) { vector<int> a = {0} , b = {1}; bool bo = are_connected(a,b); if(bo==0) { return {0,2,1}; } a = {1}, b = {2}; bo = are_connected(a,b); if(bo==1) { return {0,1,2}; } else return {1,0,2}; } vector<int> ans; ans.push_back(0); ll l = 1, r = N-1; ll lst = 0; while(l+2<r) { vector<int> a = {lst}; vector<int> b = {l}; bool bo = are_connected(a,b); if(bo==1) {lst = l, l++ , ans.push_back(lst);} else {lst = r, r--; ans.push_back(lst);} } bool l1 = are_connected({l},{l+1})&are_connected({l},{l+2}); bool l2 = are_connected({l},{l+1})&are_connected({l+1},{l+2}); bool l3 = are_connected({l+2},{l})&are_connected({l+2},{l+1}); bool wl1 = are_connected({lst},{l}); bool wl2 = are_connected({lst},{l+1}); bool wl3 = are_connected({lst},{l+2}); if(l1&l2&l3) { if(wl1) {ans.push_back(l); ans.push_back(l+1); ans.push_back(l+2);} else {ans.push_back(l+1); ans.push_back(l+2); ans.push_back(l);} } else { if(wl1&wl2) { if(l1) {ans.push_back(l+1); ans.push_back(l); ans.push_back(l+2);} else if(l2) {ans.push_back(l); ans.push_back(l+1); ans.push_back(l+2);} else if(l3) {ans.push_back(l+1); ans.push_back(l+2); ans.push_back(l);} } else if(wl1&wl3) { if(l1) {ans.push_back(l+2); ans.push_back(l); ans.push_back(l+1);} else if(l2) {ans.push_back(l); ans.push_back(l+1); ans.push_back(l+2);} else if(l3) {ans.push_back(l); ans.push_back(l+2); ans.push_back(l+1);} } else if(wl2&wl3) { if(l1) {ans.push_back(l+2); ans.push_back(l); ans.push_back(l+1);} else if(l2) {ans.push_back(l+2); ans.push_back(l+1); ans.push_back(l);} else if(l3) {ans.push_back(l+1); ans.push_back(l+2); ans.push_back(l);} } } return ans; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:35:26: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   35 |         vector<int> a = {lst};
      |                          ^~~
longesttrip.cpp:35:26: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:36:26: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   36 |         vector<int> b = {l};
      |                          ^
longesttrip.cpp:36:26: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:42:30: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   42 |     bool l1 = are_connected({l},{l+1})&are_connected({l},{l+2});
      |                              ^
longesttrip.cpp:42:30: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:42:35: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   42 |     bool l1 = are_connected({l},{l+1})&are_connected({l},{l+2});
      |                                  ~^~
longesttrip.cpp:42:35: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:42:55: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   42 |     bool l1 = are_connected({l},{l+1})&are_connected({l},{l+2});
      |                                                       ^
longesttrip.cpp:42:55: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:42:60: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   42 |     bool l1 = are_connected({l},{l+1})&are_connected({l},{l+2});
      |                                                           ~^~
longesttrip.cpp:42:60: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:43:30: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   43 |     bool l2 = are_connected({l},{l+1})&are_connected({l+1},{l+2});
      |                              ^
longesttrip.cpp:43:30: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:43:35: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   43 |     bool l2 = are_connected({l},{l+1})&are_connected({l+1},{l+2});
      |                                  ~^~
longesttrip.cpp:43:35: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:43:56: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   43 |     bool l2 = are_connected({l},{l+1})&are_connected({l+1},{l+2});
      |                                                       ~^~
longesttrip.cpp:43:56: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:43:62: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   43 |     bool l2 = are_connected({l},{l+1})&are_connected({l+1},{l+2});
      |                                                             ~^~
longesttrip.cpp:43:62: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:44:31: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   44 |     bool l3 = are_connected({l+2},{l})&are_connected({l+2},{l+1});
      |                              ~^~
longesttrip.cpp:44:31: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:44:36: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   44 |     bool l3 = are_connected({l+2},{l})&are_connected({l+2},{l+1});
      |                                    ^
longesttrip.cpp:44:36: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:44:56: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   44 |     bool l3 = are_connected({l+2},{l})&are_connected({l+2},{l+1});
      |                                                       ~^~
longesttrip.cpp:44:56: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:44:62: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   44 |     bool l3 = are_connected({l+2},{l})&are_connected({l+2},{l+1});
      |                                                             ~^~
longesttrip.cpp:44:62: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:46:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   46 |     bool wl1 = are_connected({lst},{l});
      |                               ^~~
longesttrip.cpp:46:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:46:37: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   46 |     bool wl1 = are_connected({lst},{l});
      |                                     ^
longesttrip.cpp:46:37: warning: narrowing conversion of 'l' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:47:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   47 |     bool wl2 = are_connected({lst},{l+1});
      |                               ^~~
longesttrip.cpp:47:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:47:38: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   47 |     bool wl2 = are_connected({lst},{l+1});
      |                                     ~^~
longesttrip.cpp:47:38: warning: narrowing conversion of '(l + 1)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:48:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   48 |     bool wl3 = are_connected({lst},{l+2});
      |                               ^~~
longesttrip.cpp:48:31: warning: narrowing conversion of 'lst' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:48:38: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   48 |     bool wl3 = are_connected({lst},{l+2});
      |                                     ~^~
longesttrip.cpp:48:38: warning: narrowing conversion of '(l + 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
#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...