답안 #846616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846616 2023-09-08T07:28:27 Z Trisanu_Das 가장 긴 여행 (IOI23_longesttrip) C++17
10 / 100
6 ms 760 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
 
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;
  }
  vector<int> adj[256];
  for(int i = 0; i < N; i++){
    for(int j = 0; 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(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)){
        vis[i] = true;
        ans.push_back(i);
        flag = true;
        break;
      }
    }
    if(!flag) break;
  }
  return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:31:47: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |   for(int i = 0; i < N; i++) if(adj[i].size() >= (N + 1) / 2) return adj[i];
      |                                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB non-disjoint arrays
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB non-disjoint arrays
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 760 KB Output is correct
6 Correct 5 ms 492 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB non-disjoint arrays
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB non-disjoint arrays
2 Halted 0 ms 0 KB -