Submission #916099

# Submission time Handle Problem Language Result Execution time Memory
916099 2024-01-25T09:38:18 Z chirathnirodha Longest Trip (IOI23_longesttrip) C++17
40 / 100
783 ms 2168 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={-1,-1};
    if(v2.size()>ans){
        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:40:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     if(v2.size()>ans){
      |        ~~~~~~~~~^~~~
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 Correct 0 ms 344 KB Output is correct
2 Correct 155 ms 1916 KB Output is correct
# 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 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 121 ms 1112 KB Output is correct
4 Correct 327 ms 864 KB Output is correct
5 Correct 660 ms 1612 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 116 ms 856 KB Output is correct
9 Correct 258 ms 1444 KB Output is correct
10 Correct 640 ms 1688 KB Output is correct
11 Correct 701 ms 1184 KB Output is correct
12 Correct 663 ms 1564 KB Output is correct
13 Correct 657 ms 1432 KB Output is correct
# 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 109 ms 600 KB Output is correct
4 Correct 333 ms 1124 KB Output is correct
5 Correct 660 ms 2148 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 106 ms 856 KB Output is correct
9 Correct 253 ms 652 KB Output is correct
10 Correct 674 ms 2076 KB Output is correct
11 Correct 670 ms 1624 KB Output is correct
12 Correct 666 ms 1564 KB Output is correct
13 Correct 690 ms 1596 KB Output is correct
14 Correct 7 ms 544 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 36 ms 440 KB Output is correct
17 Correct 70 ms 600 KB Output is correct
18 Correct 113 ms 856 KB Output is correct
19 Correct 261 ms 1192 KB Output is correct
20 Correct 239 ms 1236 KB Output is correct
21 Correct 669 ms 1480 KB Output is correct
22 Correct 705 ms 1672 KB Output is correct
23 Correct 665 ms 2144 KB Output is correct
24 Correct 669 ms 1848 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 19 ms 344 KB Output is correct
28 Correct 23 ms 344 KB Output is correct
29 Correct 25 ms 344 KB Output is correct
30 Correct 138 ms 960 KB Output is correct
31 Correct 153 ms 1204 KB Output is correct
32 Correct 149 ms 888 KB Output is correct
33 Correct 229 ms 1132 KB Output is correct
34 Correct 236 ms 1120 KB Output is correct
35 Correct 245 ms 1224 KB Output is correct
36 Correct 664 ms 1424 KB Output is correct
37 Correct 681 ms 1420 KB Output is correct
38 Correct 641 ms 1840 KB Output is correct
39 Correct 688 ms 1644 KB Output is correct
40 Correct 726 ms 1652 KB Output is correct
41 Correct 690 ms 1536 KB Output is correct
42 Correct 728 ms 1156 KB Output is correct
43 Correct 726 ms 1892 KB Output is correct
44 Correct 736 ms 1560 KB Output is correct
45 Correct 14 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 20 ms 344 KB Output is correct
48 Correct 21 ms 344 KB Output is correct
49 Correct 23 ms 344 KB Output is correct
50 Correct 157 ms 952 KB Output is correct
51 Correct 160 ms 944 KB Output is correct
52 Correct 146 ms 696 KB Output is correct
53 Correct 232 ms 724 KB Output is correct
54 Correct 235 ms 1484 KB Output is correct
55 Correct 239 ms 1368 KB Output is correct
56 Correct 655 ms 1188 KB Output is correct
57 Correct 682 ms 1792 KB Output is correct
58 Correct 703 ms 912 KB Output is correct
59 Correct 758 ms 1840 KB Output is correct
60 Correct 682 ms 1884 KB Output is correct
61 Correct 751 ms 1296 KB Output is correct
62 Correct 777 ms 1052 KB Output is correct
63 Correct 678 ms 1300 KB Output is correct
64 Correct 691 ms 1684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 27 ms 344 KB Output is correct
3 Partially correct 129 ms 856 KB Output is partially correct
4 Partially correct 329 ms 1224 KB Output is partially correct
5 Partially correct 680 ms 1500 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 28 ms 344 KB Output is correct
8 Partially correct 122 ms 696 KB Output is partially correct
9 Partially correct 248 ms 1876 KB Output is partially correct
10 Partially correct 688 ms 1872 KB Output is partially correct
11 Partially correct 666 ms 1796 KB Output is partially correct
12 Partially correct 783 ms 2168 KB Output is partially correct
13 Partially correct 667 ms 1660 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Incorrect 4 ms 600 KB Incorrect
17 Halted 0 ms 0 KB -