답안 #846640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846640 2023-09-08T08:06:10 Z Trisanu_Das 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
897 ms 1896 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<int> adj[404];
 
vector<int> longest_trip(int N, int d) {
    if(d == 2){
      vector<int> ans;
      int u = 0; ans.push_back(u);
      while(u < N - 1) {
          if(are_connected({u}, {u + 1})) ans.push_back(++u);
          else if(u != N - 2) {
              ans.push_back(u + 2);
              ans.push_back(u + 1);
              u += 2;
          } else {
              reverse(ans.begin(), ans.end());
              ans.push_back(N - 1);
              u++;
          }
      }
      return ans;
    }
    for(int i = 0; i < N; i++) adj[i].clear();
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {    
            if(!are_connected({i}, {j})) {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }
    for(int i = 0; i < N; i++) if((int)adj[i].size() >= (N + 1) / 2) return adj[i];
    for(int i = 0; i < N; i++) sort(adj[i].begin(), adj[i].end());
    bool vis[N]{}; vector<int> ans;
    ans.push_back(0), vis[0] = true;
    while(true) {
        bool flag = false;
        for(int i = 0; i < N; i++) {
          if(!vis[i] && !binary_search(adj[ans.back()].begin(), adj[ans.back()].end(), i)) {
            ans.push_back(i);
            vis[i] = true;
            flag = true;
            break;
          }
        }
        if(!flag) break;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Correct 135 ms 344 KB Output is correct
4 Correct 355 ms 344 KB Output is correct
5 Correct 700 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 123 ms 344 KB Output is correct
4 Correct 325 ms 344 KB Output is correct
5 Correct 712 ms 420 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 123 ms 452 KB Output is correct
9 Correct 264 ms 596 KB Output is correct
10 Correct 683 ms 436 KB Output is correct
11 Correct 706 ms 428 KB Output is correct
12 Correct 672 ms 436 KB Output is correct
13 Correct 684 ms 432 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 41 ms 344 KB Output is correct
17 Correct 77 ms 448 KB Output is correct
18 Correct 120 ms 344 KB Output is correct
19 Correct 294 ms 944 KB Output is correct
20 Correct 284 ms 1208 KB Output is correct
21 Correct 725 ms 880 KB Output is correct
22 Correct 713 ms 992 KB Output is correct
23 Correct 788 ms 724 KB Output is correct
24 Correct 781 ms 1236 KB Output is correct
25 Correct 11 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 21 ms 344 KB Output is correct
28 Correct 27 ms 344 KB Output is correct
29 Correct 22 ms 344 KB Output is correct
30 Correct 163 ms 448 KB Output is correct
31 Correct 160 ms 956 KB Output is correct
32 Correct 170 ms 712 KB Output is correct
33 Correct 277 ms 680 KB Output is correct
34 Correct 301 ms 692 KB Output is correct
35 Correct 268 ms 960 KB Output is correct
36 Correct 783 ms 436 KB Output is correct
37 Correct 672 ms 972 KB Output is correct
38 Correct 736 ms 1552 KB Output is correct
39 Correct 779 ms 1620 KB Output is correct
40 Correct 754 ms 1544 KB Output is correct
41 Correct 726 ms 1280 KB Output is correct
42 Correct 741 ms 1256 KB Output is correct
43 Correct 714 ms 1636 KB Output is correct
44 Correct 779 ms 1844 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 28 ms 344 KB Output is correct
48 Correct 25 ms 596 KB Output is correct
49 Correct 25 ms 344 KB Output is correct
50 Correct 181 ms 448 KB Output is correct
51 Correct 172 ms 964 KB Output is correct
52 Correct 178 ms 704 KB Output is correct
53 Correct 257 ms 680 KB Output is correct
54 Correct 261 ms 692 KB Output is correct
55 Correct 268 ms 1104 KB Output is correct
56 Correct 833 ms 680 KB Output is correct
57 Correct 680 ms 600 KB Output is correct
58 Correct 728 ms 1564 KB Output is correct
59 Correct 773 ms 1468 KB Output is correct
60 Correct 754 ms 1804 KB Output is correct
61 Correct 785 ms 912 KB Output is correct
62 Correct 897 ms 988 KB Output is correct
63 Correct 780 ms 1692 KB Output is correct
64 Correct 781 ms 1896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Partially correct 147 ms 344 KB Output is partially correct
4 Partially correct 360 ms 344 KB Output is partially correct
5 Partially correct 754 ms 424 KB Output is partially correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -