Submission #916076

# Submission time Handle Problem Language Result Execution time Memory
916076 2024-01-25T08:42:20 Z chirathnirodha Longest Trip (IOI23_longesttrip) C++17
5 / 100
1000 ms 2097152 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];
    for(int i=0;i<n;i++)v[i].clear();
    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})){v[i].PB(j);v[j].PB(i); 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={0,0};
    if(v2.size()>0){
        ans=v2.size();
        p1={0,0};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(true){
        int x=p1.F,y=p1.S;
        ou.PB(v1[x]);
        if(x==y)break;
        if(x>y)p1.F--;
        else p1.S++;
    }
    while(true){
        int x=p2.F,y=p2.S;
        ou.PB(v2[x]);
        if(x==y)break;
        if(x>y)p2.F--;
        else p2.S++;
    }
    return ou;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0;i<v1.size();i++){
      |                 ~^~~~~~~~~~
longesttrip.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j=0;j<v2.size();j++){
      |                     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3150 ms 2039664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 544 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 111 ms 960 KB Output is correct
4 Correct 329 ms 988 KB Output is correct
5 Correct 720 ms 1360 KB Output is correct
6 Execution timed out 1756 ms 2097152 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 119 ms 856 KB Output is correct
4 Correct 357 ms 1360 KB Output is correct
5 Correct 735 ms 1632 KB Output is correct
6 Execution timed out 1636 ms 2097152 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 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 Partially correct 120 ms 864 KB Output is partially correct
4 Partially correct 357 ms 1228 KB Output is partially correct
5 Partially correct 704 ms 1208 KB Output is partially correct
6 Execution timed out 1710 ms 2097152 KB Time limit exceeded
7 Halted 0 ms 0 KB -