Submission #1007030

# Submission time Handle Problem Language Result Execution time Memory
1007030 2024-06-24T10:59:49 Z Amr Longest Trip (IOI23_longesttrip) C++17
15 / 100
11 ms 440 KB
#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

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 time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 440 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
14 Incorrect 0 ms 344 KB Incorrect
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 7 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
14 Incorrect 0 ms 344 KB Incorrect
15 Halted 0 ms 0 KB -