Submission #916081

# Submission time Handle Problem Language Result Execution time Memory
916081 2024-01-25T08:52:22 Z chirathnirodha Longest Trip (IOI23_longesttrip) C++17
15 / 100
738 ms 596 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define P push
#define I insert 
#define F first
#define S second
typedef long long ll;

vector<int> longest_trip(int n, int D){
    if(D==3){
        vector<int> tt;for(int i=0;i<n;i++)tt.PB(i);
        return tt;
    }
    vector<int> v[n];
    bool grid[n][n];
    memset(grid,0,sizeof(grid));

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(are_connected({i},{j}))grid[i][j]=grid[j][i]=1;
        }
    }
    vector<int> v1,v2;
    v1.PB(0);v2.PB(1);
    for(int i=2;i<n;i++){
        if(grid[i][v1.back()])v1.PB(i);
        else if(grid[i][v2.back()])v2.PB(i);
        else{
            for(int j=v2.size()-1;j>=0;j--)v1.PB(v2[j]);
            v2.clear();
            v2.PB(i);
        }
    }
    int ans=v1.size();
    pair<int,int> p1={0,v1.size()-1},p2={-1,-1};
    if(v2.size()>0){
        ans=v2.size();
        p1={-1,-1};p2={0,v2.size()-1};
    }
    for(int i=0;i<v1.size();i++){
        int x=v1[i];
        for(int j=0;j<v2.size();j++){
            int y=v2[j];
            if(!grid[x][y])continue;
            int cur;
            cur= i+1 + j+1 ;if(cur>ans){ans=cur;p1={0,i};p2={j,0};}
            cur= i+1 + v2.size()-j ;if(cur>ans){ans=cur;p1={0,i};p2={j,v2.size()-1};}
            cur= v1.size()-i + j+1 ;if(cur>ans){ans=cur;p1={v1.size()-1,i};p2={j,0};}
            cur= v1.size()-i + v2.size()-j ;if(cur>ans){ans=cur;p1={v1.size()-1,i};p2={j,v2.size()-1};}
        }
    }
    vector<int> ou;
    while(p1.F>=0 && p1.S>=0){
        int x=p1.F,y=p1.S;
        ou.PB(v1[x]);
        if(x==y)break;
        if(x>y)p1.F--;
        else p1.F++;
    }
    while(p2.F>=0 && p2.S>=0){
        int x=p2.F,y=p2.S;
        ou.PB(v2[x]);
        if(x==y)break;
        if(x>y)p2.F--;
        else p2.F++;
    }
    return ou;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0;i<v1.size();i++){
      |                 ~^~~~~~~~~~
longesttrip.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j=0;j<v2.size();j++){
      |                     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 158 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 115 ms 344 KB Output is correct
4 Correct 310 ms 344 KB Output is correct
5 Correct 701 ms 476 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 135 ms 344 KB Output is correct
9 Correct 260 ms 344 KB Output is correct
10 Correct 702 ms 484 KB Output is correct
11 Correct 685 ms 480 KB Output is correct
12 Correct 701 ms 484 KB Output is correct
13 Correct 686 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 115 ms 344 KB Output is correct
4 Correct 334 ms 344 KB Output is correct
5 Correct 738 ms 476 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 115 ms 596 KB Output is correct
9 Correct 226 ms 344 KB Output is correct
10 Correct 731 ms 476 KB Output is correct
11 Correct 663 ms 484 KB Output is correct
12 Correct 709 ms 484 KB Output is correct
13 Correct 694 ms 480 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Incorrect 5 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Partially correct 123 ms 344 KB Output is partially correct
4 Partially correct 295 ms 344 KB Output is partially correct
5 Partially correct 724 ms 480 KB Output is partially correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Partially correct 125 ms 344 KB Output is partially correct
9 Partially correct 264 ms 344 KB Output is partially correct
10 Partially correct 659 ms 480 KB Output is partially correct
11 Partially correct 672 ms 484 KB Output is partially correct
12 Partially correct 696 ms 476 KB Output is partially correct
13 Partially correct 689 ms 484 KB Output is partially correct
14 Incorrect 0 ms 344 KB Incorrect
15 Halted 0 ms 0 KB -