Submission #927716

# Submission time Handle Problem Language Result Execution time Memory
927716 2024-02-15T09:18:29 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
776 ms 1108 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

int A[300][300];

int ask(vector<int> a, vector<int> b)
{
    for (int x : a)
    {
        for (int y : b)
        {
            if (A[x][y]) return 1;
        }
    }
    return 0;
}

vector<int> longest_trip(int n, int D)
{
    for (int i = 0; i < n; i++)
    {
        A[i][i] = 1;
        for (int j = i + 1; j < n; j++)
        {
            A[i][j] = A[j][i] = are_connected({i}, {j});
        }
    }
    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 (ask({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() && ask(v1, {i}) && ask(v2, {i})) 
        {
            int id1 = -1, id2 = -1;
            for (int j = 0; j < v1.size(); j++)
            {
                if (ask({v1[j]}, {i}))
                {
                    id1 = j;
                    break;
                }
            }
            for (int j = 0; j < v2.size(); j++)
            {
                if (ask({v2[j]}, {i}))
                {
                    id2 = j;
                    break;
                }
            }
            cur.clear();
            for (int j = (id2 + 1) % v2.size(); 1; j = (j + 1) % v2.size())
            {
                cur.push_back(v2[j]);
                if (j == id2) break;
            }
            cur.push_back(i), cur.push_back(v1[id1]);
            for (int j = (id1 + 1) % v1.size(); j != id1; j = (j + 1) % v1.size())
            {
                cur.push_back(v1[j]);
            }
            v2.clear();
            v1 = cur;
        }
        else if (ask(v1, {i})) 
        {
            vector<int> nw;
            int idx = -1;
            for (int j = 0; j < v1.size(); j++) 
            {
                if (ask({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 (ask({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;
            }
        }
    }
    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:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for (int j = 0; j < v1.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:59:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for (int j = 0; j < v2.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:85:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for (int j = 0; j < v1.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:107:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |                 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 189 ms 716 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 20 ms 344 KB Output is correct
3 Correct 131 ms 600 KB Output is correct
4 Correct 339 ms 592 KB Output is correct
5 Correct 689 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 120 ms 716 KB Output is correct
4 Correct 351 ms 568 KB Output is correct
5 Correct 639 ms 720 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 32 ms 344 KB Output is correct
8 Correct 114 ms 500 KB Output is correct
9 Correct 286 ms 592 KB Output is correct
10 Correct 759 ms 716 KB Output is correct
11 Correct 727 ms 856 KB Output is correct
12 Correct 709 ms 724 KB Output is correct
13 Correct 735 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 122 ms 504 KB Output is correct
4 Correct 376 ms 564 KB Output is correct
5 Correct 776 ms 720 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 110 ms 344 KB Output is correct
9 Correct 266 ms 540 KB Output is correct
10 Correct 758 ms 716 KB Output is correct
11 Correct 681 ms 724 KB Output is correct
12 Correct 687 ms 716 KB Output is correct
13 Correct 769 ms 720 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 7 ms 344 KB Output is correct
2 Correct 23 ms 344 KB Output is correct
3 Partially correct 134 ms 600 KB Output is partially correct
4 Partially correct 348 ms 344 KB Output is partially correct
5 Partially correct 755 ms 1108 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 26 ms 344 KB Output is correct
8 Partially correct 110 ms 600 KB Output is partially correct
9 Partially correct 281 ms 548 KB Output is partially correct
10 Partially correct 756 ms 724 KB Output is partially correct
11 Partially correct 697 ms 716 KB Output is partially correct
12 Partially correct 735 ms 724 KB Output is partially correct
13 Partially correct 742 ms 716 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Incorrect 4 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -