Submission #928448

# Submission time Handle Problem Language Result Execution time Memory
928448 2024-02-16T12:05:22 Z aykhn Longest Trip (IOI23_longesttrip) C++17
15 / 100
25 ms 2336 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
 
using namespace std;
 
int A[300][300];
map<pair<vector<int>, vector<int>>, int> mp;
 
int ask(vector<int> a, vector<int> b)
{
    if (a.empty() || b.empty()) return 0;
    if (mp.find({a, b}) != mp.end()) return mp[{a, b}];
    return mp[{a, b}] = mp[{b, a}] = are_connected(a, b);
}
 
vector<int> longest_trip(int n, int D)
{
    mp.clear();
    vector<int> v1, v2;
    v1.push_back(0);
    for (int i = 1; i < n; i++)
    {
        if (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;
                }
            }
            vector<int> nw;
            for (int j = (id2 + 1) % v2.size(); 1; j = (j + 1) % v2.size())
            {
                nw.push_back(v2[j]);
                if (j == id2) break;
            }
            nw.push_back(i), nw.push_back(v1[id1]);
            for (int j = (id1 + 1) % v1.size(); j != id1; j = (j + 1) % v1.size())
            {
                nw.push_back(v1[j]);
            }
            v2.clear();
            v1 = nw;
        }
        else if (ask(v1, {i})) 
        {
            vector<int> nw;
            if (ask({v1[0]}, {i})) 
            {
                nw.push_back(i);
                for (int x : v1) nw.push_back(x);
            }
            else if (ask({v1.back()}, {i}))
            {
                nw = v1;
                nw.push_back(i);
            }
            else
            {
                int l = 0, r = (int)v1.size() - 1;
                while (l < r)
                {
                    int mid = (l + r) >> 1;
                    vector<int> x;
                    for (int j = 0; j <= mid; j++)
                    {
                        x.push_back(v1[j]);
                        if (ask(x, {i})) r = mid;
                        else l = mid + 1;
                    }
                }
                int idx = l;
                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 (ask(v2, {i}))
        {
            vector<int> nw;
            if (ask({v2[0]}, {i})) 
            {
                nw.push_back(i);
                for (int x : v2) nw.push_back(x);
            }
            else if (ask({v2.back()}, {i}))
            {
                nw = v2;
                nw.push_back(i);
            }
            else
            {
                int l = 0, r = (int)v2.size() - 1;
                while (l < r)
                {
                    int mid = (l + r) >> 1;
                    vector<int> x;
                    for (int j = 0; j <= mid; j++)
                    {
                        x.push_back(v2[j]);
                        if (ask(x, {i})) r = mid;
                        else l = mid + 1;
                    }
                }
                int idx = l;
                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;
        }
        else v2.push_back(i);
    }
    if (v1.size() > v2.size()) return v1;
    else return v2;
};

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:26:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for (int j = 0; j < v1.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:34:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             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 12 ms 1700 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 12 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 15 ms 812 KB Output is correct
5 Correct 22 ms 1344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 16 ms 808 KB Output is correct
5 Correct 20 ms 1404 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 14 ms 600 KB Output is correct
9 Correct 15 ms 804 KB Output is correct
10 Correct 21 ms 1536 KB Output is correct
11 Correct 21 ms 1460 KB Output is correct
12 Correct 22 ms 2336 KB Output is correct
13 Correct 22 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 18 ms 896 KB Output is correct
5 Correct 22 ms 1348 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 13 ms 344 KB Output is correct
8 Correct 13 ms 344 KB Output is correct
9 Correct 15 ms 768 KB Output is correct
10 Correct 22 ms 1152 KB Output is correct
11 Correct 22 ms 1832 KB Output is correct
12 Correct 22 ms 1144 KB Output is correct
13 Correct 21 ms 1648 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 16 ms 1064 KB Output is correct
5 Partially correct 25 ms 1180 KB Output is partially correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 15 ms 1024 KB Output is correct
10 Partially correct 21 ms 1500 KB Output is partially correct
11 Partially correct 21 ms 1144 KB Output is partially correct
12 Partially correct 21 ms 1368 KB Output is partially correct
13 Partially correct 22 ms 1748 KB Output is partially correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -