답안 #861649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861649 2023-10-16T15:36:43 Z faustaadp 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
848 ms 5208 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
const ll NN = 1e5 + 5;
vector<int> ret, ret2;
ll b[NN], n, ada = 0, mxx, now, coba = 0, ti;
vector<ll> v[NN];
void dfs(ll pos)
{
    if(ada)return ;
    b[pos] = 1;
    ret.pb(pos);
    // cout << pos << " mas " << ret.size() << "_\n";
    // cout << ret.size() << " dan " << mxx << "\n";
    coba++;
    if(ret2.size() < ret.size())ret2 = ret;
    if(coba >= n * 5)ada = 2;
    // if(ret.size() * 2 >= mxx)ada = 1;
    if(ada)return;
    // random_shuffle(v[pos].begin(), v[pos].end());
    for(ll i = 0; i < v[pos].size(); i++)
    {
        if(b[v[pos][i]] == 0)dfs(v[pos][i]);
        if(ada)return ;
    }
    b[pos] = 0;
    // cout << pos << " kel\n";
    ret.pop_back();
}
void dfs2(ll pos)
{
    now++;
    mxx = max(mxx, now);
    b[pos] = ti;
    for(ll i = 0; i < v[pos].size(); i++)
        if(b[v[pos][i]] == 0)
            dfs2(v[pos][i]);
}
std::vector<int> longest_trip(int N, int D)
{
    ret2.clear();
    mxx = 0;
    coba = 0;
    ada = 0;
    n = N;
    ret.clear();
    for(ll i = 0; i < N; i++)
    {
        v[i].clear();
        b[i] = 0;
    }
    for(ll i = 0; i < N; i++)
        for(ll j = i + 1; j < N; j++)
        {
            vector<int> A;A.pb(i);
            vector<int> B;B.pb(j);
            bool isi = are_connected(A, B);
            if(isi)
            {
                // cout << i << "--" << j << "\n";
                v[i].pb(j);
                v[j].pb(i);
            }
        }
    for(ll i = 0; i < N; i++)
        if(!b[i])
        {
            ti++;
            now = 0;
            dfs2(i);
        }
    for(ll i = 0; i < N; i++)
    {
        b[i] = 0;
    }
    ti = 1;
    vector<ll> cal;
    for(ll i = 0; i < N; i++)
        if(!b[i])
        {
            ti++;
            now = 0;
            dfs2(i);
            if(now != mxx)
                continue;
            for(ll j = 0; j < N; j++)
            {
                if(b[j] == ti)
                    cal.pb(j);
            }
            break;
        }
    memset(b, 0, sizeof(b));
    for(ll i = 0; i < N; i++)
    {
        coba = 0;
        dfs(i);
        ret.clear();
        if(ada == 2)ada = 0;
        if(ret.size() == mxx)break;
    }
    return ret2;
    // ll mul = 1;
    // if(N % 2 == 0)
    // {
    //     vector<int> A;A.pb(0);
    //     vector<int> B;B.pb(1);
    //     bool isi = are_connected(A, B);
    //     if(!isi)
    //         swap(cal[1], cal[2]);
    //     ret.pb(cal[0]);
    //     ret.pb(cal[1]);
    // }
    // else
    //     ret.pb(cal[0]);
    // for(ll i = mul; i + 1 < N; i += 2)
    // {
    //     ll now = ret.back();
    //     vector<int> A;A.pb(now);
    //     vector<int> B;A.pb(cal[i]);
    //     bool isi = are_connected(A, B);
    //     if()
    // }
    // return ret;
}

Compilation message

longesttrip.cpp: In function 'void dfs(ll)':
longesttrip.cpp:23:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'void dfs2(ll)':
longesttrip.cpp:37:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:102:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  102 |         if(ret.size() == mxx)break;
      |            ~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 198 ms 4552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3416 KB Output is correct
2 Correct 23 ms 3416 KB Output is correct
3 Correct 126 ms 3944 KB Output is correct
4 Correct 370 ms 3868 KB Output is correct
5 Correct 795 ms 4592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3416 KB Output is correct
2 Correct 23 ms 3416 KB Output is correct
3 Correct 117 ms 3672 KB Output is correct
4 Correct 375 ms 3916 KB Output is correct
5 Correct 788 ms 4244 KB Output is correct
6 Correct 15 ms 3416 KB Output is correct
7 Correct 21 ms 3672 KB Output is correct
8 Correct 122 ms 3672 KB Output is correct
9 Correct 264 ms 4084 KB Output is correct
10 Correct 807 ms 4348 KB Output is correct
11 Correct 787 ms 4112 KB Output is correct
12 Correct 781 ms 4348 KB Output is correct
13 Correct 824 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3416 KB Output is correct
2 Correct 26 ms 3416 KB Output is correct
3 Correct 126 ms 3696 KB Output is correct
4 Correct 365 ms 3880 KB Output is correct
5 Correct 830 ms 4188 KB Output is correct
6 Correct 15 ms 3416 KB Output is correct
7 Correct 22 ms 3416 KB Output is correct
8 Correct 130 ms 3692 KB Output is correct
9 Correct 300 ms 4176 KB Output is correct
10 Correct 805 ms 4600 KB Output is correct
11 Correct 770 ms 4276 KB Output is correct
12 Correct 789 ms 4608 KB Output is correct
13 Correct 791 ms 4604 KB Output is correct
14 Correct 13 ms 3416 KB Output is correct
15 Correct 14 ms 3416 KB Output is correct
16 Correct 36 ms 3684 KB Output is correct
17 Correct 68 ms 3672 KB Output is correct
18 Correct 124 ms 3928 KB Output is correct
19 Correct 272 ms 4116 KB Output is correct
20 Correct 270 ms 3828 KB Output is correct
21 Correct 776 ms 4428 KB Output is correct
22 Correct 776 ms 4628 KB Output is correct
23 Correct 797 ms 4164 KB Output is correct
24 Correct 816 ms 4568 KB Output is correct
25 Correct 15 ms 3416 KB Output is correct
26 Correct 14 ms 3416 KB Output is correct
27 Correct 26 ms 3668 KB Output is correct
28 Correct 23 ms 3416 KB Output is correct
29 Correct 22 ms 3416 KB Output is correct
30 Correct 158 ms 4076 KB Output is correct
31 Correct 168 ms 4360 KB Output is correct
32 Correct 156 ms 4076 KB Output is correct
33 Correct 265 ms 3940 KB Output is correct
34 Correct 279 ms 4124 KB Output is correct
35 Correct 265 ms 3792 KB Output is correct
36 Correct 791 ms 4332 KB Output is correct
37 Correct 791 ms 4404 KB Output is correct
38 Correct 805 ms 5208 KB Output is correct
39 Correct 816 ms 4912 KB Output is correct
40 Correct 728 ms 4776 KB Output is correct
41 Correct 747 ms 4548 KB Output is correct
42 Correct 816 ms 4472 KB Output is correct
43 Correct 767 ms 5040 KB Output is correct
44 Correct 743 ms 5116 KB Output is correct
45 Correct 13 ms 3416 KB Output is correct
46 Correct 15 ms 3416 KB Output is correct
47 Correct 24 ms 3672 KB Output is correct
48 Correct 23 ms 3412 KB Output is correct
49 Correct 25 ms 3672 KB Output is correct
50 Correct 173 ms 3820 KB Output is correct
51 Correct 169 ms 4104 KB Output is correct
52 Correct 167 ms 3824 KB Output is correct
53 Correct 271 ms 4144 KB Output is correct
54 Correct 270 ms 3732 KB Output is correct
55 Correct 278 ms 3680 KB Output is correct
56 Correct 802 ms 4400 KB Output is correct
57 Correct 831 ms 4912 KB Output is correct
58 Correct 793 ms 4868 KB Output is correct
59 Correct 790 ms 4868 KB Output is correct
60 Correct 743 ms 4972 KB Output is correct
61 Correct 802 ms 4408 KB Output is correct
62 Correct 834 ms 4036 KB Output is correct
63 Correct 779 ms 5140 KB Output is correct
64 Correct 819 ms 5124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3416 KB Output is correct
2 Correct 27 ms 3416 KB Output is correct
3 Partially correct 136 ms 3592 KB Output is partially correct
4 Partially correct 378 ms 4236 KB Output is partially correct
5 Partially correct 832 ms 4712 KB Output is partially correct
6 Correct 13 ms 3416 KB Output is correct
7 Correct 23 ms 3416 KB Output is correct
8 Partially correct 121 ms 4184 KB Output is partially correct
9 Partially correct 304 ms 3988 KB Output is partially correct
10 Partially correct 819 ms 4584 KB Output is partially correct
11 Partially correct 848 ms 4364 KB Output is partially correct
12 Partially correct 793 ms 4360 KB Output is partially correct
13 Partially correct 826 ms 4356 KB Output is partially correct
14 Correct 14 ms 3416 KB Output is correct
15 Correct 17 ms 3668 KB Output is correct
16 Incorrect 3 ms 3416 KB Incorrect
17 Halted 0 ms 0 KB -