답안 #841577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841577 2023-09-01T17:29:41 Z flashmt 가장 긴 여행 (IOI23_longesttrip) C++17
60 / 100
781 ms 848 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> longest_trip(int n, int d)
{
  if (d == 3)
  {
    vector<int> ans(n);
    iota(begin(ans), end(ans), 0);
    return ans;
  }

  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      a[i][j] = a[j][i] = are_connected({i}, {j});

  auto addToPath = [&](vector<int> &path, int x)
  {
    if (a[x][path[0]]) path.insert(begin(path), x);
    else if (a[x][path.back()]) path.push_back(x);
    else
    {
      for (int i = 0; i < size(path); i++)
        if (a[x][path[i]])
        {
          rotate(begin(path), begin(path) + (i + 1), end(path));
          path.push_back(x);
          return;
        }
    }
  };

  vector<int> seen(n);
  vector<int> ans;
  for (int i = 0; i < n; i++)
    if (!seen[i])
    {
      queue<int> q;
      q.push(i);
      seen[i] = 1;
      vector<int> path = {i};
      while (!empty(q))
      {
        int x = q.front();
        q.pop();
        for (int y = 0; y < n; y++)
          if (!seen[y] && a[x][y])
          {
            seen[y] = 1;
            q.push(y);
            addToPath(path, y);
          }
      }

      if (size(path) > size(ans))
        ans = path;
    }

  return ans;
}

Compilation message

longesttrip.cpp: In lambda function:
longesttrip.cpp:25:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |       for (int i = 0; i < size(path); i++)
      |                       ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 167 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 114 ms 344 KB Output is correct
4 Correct 298 ms 592 KB Output is correct
5 Correct 731 ms 684 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 119 ms 344 KB Output is correct
9 Correct 240 ms 344 KB Output is correct
10 Correct 662 ms 684 KB Output is correct
11 Correct 718 ms 680 KB Output is correct
12 Correct 682 ms 684 KB Output is correct
13 Correct 652 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 112 ms 340 KB Output is correct
4 Correct 312 ms 476 KB Output is correct
5 Correct 700 ms 676 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 115 ms 344 KB Output is correct
9 Correct 231 ms 344 KB Output is correct
10 Correct 701 ms 676 KB Output is correct
11 Correct 698 ms 684 KB Output is correct
12 Correct 699 ms 680 KB Output is correct
13 Correct 676 ms 676 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 41 ms 344 KB Output is correct
17 Correct 68 ms 600 KB Output is correct
18 Correct 118 ms 344 KB Output is correct
19 Correct 265 ms 344 KB Output is correct
20 Correct 248 ms 344 KB Output is correct
21 Correct 706 ms 680 KB Output is correct
22 Correct 683 ms 680 KB Output is correct
23 Correct 676 ms 676 KB Output is correct
24 Correct 713 ms 680 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 11 ms 344 KB Output is correct
27 Correct 22 ms 344 KB Output is correct
28 Correct 20 ms 344 KB Output is correct
29 Correct 22 ms 344 KB Output is correct
30 Correct 149 ms 344 KB Output is correct
31 Correct 149 ms 344 KB Output is correct
32 Correct 148 ms 344 KB Output is correct
33 Correct 256 ms 344 KB Output is correct
34 Correct 248 ms 344 KB Output is correct
35 Correct 253 ms 344 KB Output is correct
36 Correct 715 ms 680 KB Output is correct
37 Correct 689 ms 680 KB Output is correct
38 Correct 626 ms 680 KB Output is correct
39 Correct 678 ms 680 KB Output is correct
40 Correct 669 ms 680 KB Output is correct
41 Correct 697 ms 600 KB Output is correct
42 Correct 692 ms 600 KB Output is correct
43 Correct 701 ms 680 KB Output is correct
44 Correct 695 ms 676 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 9 ms 596 KB Output is correct
47 Correct 24 ms 344 KB Output is correct
48 Correct 28 ms 344 KB Output is correct
49 Correct 23 ms 344 KB Output is correct
50 Correct 158 ms 344 KB Output is correct
51 Correct 167 ms 344 KB Output is correct
52 Correct 154 ms 344 KB Output is correct
53 Correct 252 ms 344 KB Output is correct
54 Correct 263 ms 344 KB Output is correct
55 Correct 252 ms 344 KB Output is correct
56 Correct 709 ms 684 KB Output is correct
57 Correct 781 ms 688 KB Output is correct
58 Correct 720 ms 688 KB Output is correct
59 Correct 731 ms 676 KB Output is correct
60 Correct 703 ms 676 KB Output is correct
61 Correct 745 ms 680 KB Output is correct
62 Correct 739 ms 684 KB Output is correct
63 Correct 707 ms 680 KB Output is correct
64 Correct 693 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Partially correct 109 ms 344 KB Output is partially correct
4 Partially correct 340 ms 476 KB Output is partially correct
5 Partially correct 742 ms 684 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 115 ms 344 KB Output is partially correct
9 Partially correct 257 ms 344 KB Output is partially correct
10 Partially correct 688 ms 680 KB Output is partially correct
11 Partially correct 698 ms 684 KB Output is partially correct
12 Partially correct 665 ms 680 KB Output is partially correct
13 Partially correct 689 ms 676 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 37 ms 344 KB Output is correct
17 Partially correct 77 ms 440 KB Output is partially correct
18 Partially correct 109 ms 344 KB Output is partially correct
19 Partially correct 254 ms 344 KB Output is partially correct
20 Partially correct 237 ms 344 KB Output is partially correct
21 Correct 11 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 18 ms 344 KB Output is correct
24 Correct 23 ms 344 KB Output is correct
25 Correct 24 ms 344 KB Output is correct
26 Partially correct 150 ms 344 KB Output is partially correct
27 Partially correct 145 ms 344 KB Output is partially correct
28 Partially correct 155 ms 344 KB Output is partially correct
29 Partially correct 244 ms 344 KB Output is partially correct
30 Partially correct 265 ms 596 KB Output is partially correct
31 Partially correct 250 ms 344 KB Output is partially correct
32 Correct 8 ms 596 KB Output is correct
33 Correct 7 ms 344 KB Output is correct
34 Correct 19 ms 344 KB Output is correct
35 Correct 19 ms 344 KB Output is correct
36 Correct 21 ms 344 KB Output is correct
37 Partially correct 152 ms 344 KB Output is partially correct
38 Partially correct 152 ms 344 KB Output is partially correct
39 Partially correct 148 ms 344 KB Output is partially correct
40 Partially correct 257 ms 600 KB Output is partially correct
41 Partially correct 239 ms 344 KB Output is partially correct
42 Partially correct 249 ms 344 KB Output is partially correct
43 Partially correct 687 ms 676 KB Output is partially correct
44 Partially correct 664 ms 680 KB Output is partially correct
45 Partially correct 709 ms 848 KB Output is partially correct
46 Partially correct 667 ms 680 KB Output is partially correct
47 Partially correct 720 ms 680 KB Output is partially correct
48 Partially correct 689 ms 680 KB Output is partially correct
49 Partially correct 671 ms 676 KB Output is partially correct
50 Partially correct 684 ms 684 KB Output is partially correct
51 Partially correct 673 ms 680 KB Output is partially correct
52 Partially correct 735 ms 600 KB Output is partially correct
53 Partially correct 728 ms 600 KB Output is partially correct
54 Partially correct 728 ms 676 KB Output is partially correct
55 Partially correct 701 ms 680 KB Output is partially correct
56 Partially correct 673 ms 676 KB Output is partially correct
57 Partially correct 690 ms 676 KB Output is partially correct
58 Partially correct 721 ms 688 KB Output is partially correct
59 Partially correct 673 ms 676 KB Output is partially correct
60 Partially correct 704 ms 600 KB Output is partially correct
61 Partially correct 655 ms 600 KB Output is partially correct
62 Partially correct 702 ms 676 KB Output is partially correct
63 Partially correct 690 ms 676 KB Output is partially correct
64 Partially correct 653 ms 684 KB Output is partially correct
65 Partially correct 707 ms 676 KB Output is partially correct
66 Partially correct 689 ms 680 KB Output is partially correct
67 Partially correct 713 ms 676 KB Output is partially correct
68 Partially correct 657 ms 676 KB Output is partially correct
69 Partially correct 677 ms 676 KB Output is partially correct
70 Partially correct 721 ms 676 KB Output is partially correct
71 Partially correct 682 ms 848 KB Output is partially correct
72 Partially correct 665 ms 684 KB Output is partially correct
73 Partially correct 721 ms 680 KB Output is partially correct
74 Partially correct 701 ms 676 KB Output is partially correct
75 Partially correct 709 ms 676 KB Output is partially correct
76 Partially correct 767 ms 684 KB Output is partially correct
77 Partially correct 754 ms 680 KB Output is partially correct
78 Partially correct 765 ms 676 KB Output is partially correct
79 Partially correct 728 ms 684 KB Output is partially correct
80 Partially correct 700 ms 684 KB Output is partially correct
81 Partially correct 768 ms 684 KB Output is partially correct
82 Partially correct 727 ms 676 KB Output is partially correct