Submission #927680

# Submission time Handle Problem Language Result Execution time Memory
927680 2024-02-15T08:36:23 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
24 ms 1172 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
 
using namespace std;
 
vector<int> longest_trip(int n, int D)
{
    vector<int> used(n, 0);
    vector<int> v1, v2, cur;
    for (int i = 0; i < 3; i++)
    {
        for (int j = i + 1; j < 3; j++)
        {
            if (are_connected({i}, {j}))
            {
                v1.push_back(i), v1.push_back(j);
                used[i] = used[j] = 1;
                break;
            }
        }
        if (!v1.empty()) break;
    }
    for (int i = 0; i < n; i++)
    {
        if (used[i]) continue;
        if (!v1.empty() && !v2.empty() && are_connected(v1, {i}) && are_connected(v2, {i})) 
        {
            cur.clear();
            for (int x : v1) cur.push_back(x);
            cur.push_back(i);
            for (int x : v2) cur.push_back(x);
            v1 = cur;
          v2.clear();
        }
        else if (are_connected(v1, {i})) 
        {
            vector<int> nw;
            int idx = -1;
            for (int j = 0; j < v1.size(); j++) 
            {
                if (are_connected({i}, {v1[j]})) 
                {
                    idx = j;
                    break;
                }
            }
            nw.push_back(i), nw.push_back(v1[idx]);
            for (int j = (idx + 1) % v1.size(); j != idx; j = (j + 1) % v1.size())
            {
                nw.push_back(v1[j]);
            }
            v1 = nw;
        }
        else 
        {
            if (v2.empty()) v2.push_back(i);
            else
            {
                vector<int> nw;
                int idx = -1;
                for (int j = 0; j < v2.size(); j++) 
                {
                    if (are_connected({i}, {v2[j]})) 
                    {
                        idx = j;
                        break;
                    }
                }
                nw.push_back(i), nw.push_back(v2[idx]);
                for (int j = (idx + 1) % v2.size(); j != idx; j = (j + 1) % v2.size())
                {
                    nw.push_back(v2[j]);
                }
                v2 = nw;
            }
        }
        // cout << i << ":\n";
        // for (int x : v1) cout << x << ' ';
        // cout << '\n';
        // for (int x : v2) cout << x << ' ';
        // cout << '\n';
        // for (int x : cur) cout << x << ' ';
        // cout << '\n';
    }
    if (max({v1.size(), v2.size(), cur.size()}) == v1.size()) return v1;
    if (max({v1.size(), v2.size(), cur.size()}) == v2.size()) return v2;
    return cur;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int j = 0; j < v1.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:61:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for (int j = 0; j < v2.size(); j++)
      |                                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 5 ms 752 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 11 ms 432 KB Output is correct
4 Correct 15 ms 700 KB Output is correct
5 Correct 22 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 12 ms 600 KB Output is correct
4 Correct 13 ms 452 KB Output is correct
5 Correct 24 ms 756 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 11 ms 356 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 22 ms 700 KB Output is correct
11 Correct 21 ms 988 KB Output is correct
12 Correct 19 ms 500 KB Output is correct
13 Correct 18 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 14 ms 696 KB Output is correct
5 Correct 18 ms 736 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 11 ms 340 KB Output is correct
9 Correct 12 ms 440 KB Output is correct
10 Correct 18 ms 500 KB Output is correct
11 Correct 19 ms 504 KB Output is correct
12 Correct 20 ms 952 KB Output is correct
13 Correct 19 ms 500 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 2 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 11 ms 344 KB Output is correct
3 Correct 11 ms 344 KB Output is correct
4 Correct 13 ms 696 KB Output is correct
5 Partially correct 22 ms 1172 KB Output is partially correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Partially correct 18 ms 504 KB Output is partially correct
11 Partially correct 18 ms 504 KB Output is partially correct
12 Partially correct 19 ms 500 KB Output is partially correct
13 Partially correct 19 ms 756 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -