답안 #938938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938938 2024-03-05T22:16:36 Z AdamGS 가장 긴 여행 (IOI23_longesttrip) C++17
100 / 100
12 ms 952 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
  vector<pair<int,int>>X, Y;
  vector<int>A, B;
  rep(i, n/2) if(are_connected({2*i}, {2*i+1})) X.pb({2*i, 2*i+1}); else Y.pb({2*i, 2*i+1});
  if(n%2==1) A.pb(n-1);
  for(auto i : X) {
    if(A.size()==0) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(B.size()==0) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(are_connected({A.back()}, {i.st})) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(are_connected({B.back()}, {i.st})) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.st);
    B.pb(i.nd);
  }
  for(auto i : Y) {
    if(A.size()==0) {
      A.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(!are_connected({A.back()}, {i.st})) swap(i.st, i.nd);
    A.pb(i.st);
    if(B.size()==0 || are_connected({B.back()}, {i.nd})) {
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.nd);
  }
  if(A.size()==n) return A;
  if(!are_connected(A, B)) {
    if(A.size()<B.size()) return B;
    return A;
  }
  if(are_connected({A.back()}, {B.back()})) {
    reverse(all(B));
    for(auto i : B) A.pb(i);
    return A;
  }
  if(are_connected({A.back()}, {B[0]})) {
    for(auto i : B) A.pb(i);
    return A;
  }
  if(are_connected({A[0]}, {B.back()})) {
    for(auto i : A) B.pb(i);
    return B;
  }
  if(are_connected({A[0]}, {B[0]})) {
    reverse(all(A));
    for(auto i : B) A.pb(i);
    return A;
  }
  int po=0, ko=A.size()-1;
  while(po<ko) {
    int sr=(po+ko)/2;
    vector<int>C;
    rep(i, sr+1) C.pb(A[i]);
    if(are_connected(C, B)) ko=sr; else po=sr+1;
  }
  int x=po;
  po=0; ko=B.size()-1;
  while(po<ko) {
    int sr=(po+ko)/2;
    vector<int>C, D;
    rep(i, x+1) C.pb(A[i]);
    rep(i, sr+1) D.pb(B[i]);
    if(are_connected(C, D)) ko=sr; else po=sr+1;
  }
  int y=po;
  vector<int>ans;
  rep(i, A.size()) ans.pb(A[(x+i+1)%A.size()]);
  rep(i, B.size()) ans.pb(B[(y+i)%B.size()]);
  return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:58:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |   if(A.size()==n) return A;
      |      ~~~~~~~~^~~
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
longesttrip.cpp:99:3: note: in expansion of macro 'rep'
   99 |   rep(i, A.size()) ans.pb(A[(x+i+1)%A.size()]);
      |   ^~~
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
longesttrip.cpp:100:3: note: in expansion of macro 'rep'
  100 |   rep(i, B.size()) ans.pb(B[(y+i)%B.size()]);
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 608 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 4 ms 440 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 500 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 416 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 600 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
14 Correct 6 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 5 ms 600 KB Output is correct
21 Correct 5 ms 440 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 5 ms 440 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 5 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 6 ms 600 KB Output is correct
39 Correct 5 ms 344 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 6 ms 600 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 7 ms 344 KB Output is correct
45 Correct 12 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 8 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Correct 11 ms 344 KB Output is correct
50 Correct 5 ms 436 KB Output is correct
51 Correct 7 ms 432 KB Output is correct
52 Correct 8 ms 432 KB Output is correct
53 Correct 5 ms 344 KB Output is correct
54 Correct 5 ms 436 KB Output is correct
55 Correct 6 ms 600 KB Output is correct
56 Correct 6 ms 600 KB Output is correct
57 Correct 6 ms 608 KB Output is correct
58 Correct 6 ms 604 KB Output is correct
59 Correct 7 ms 696 KB Output is correct
60 Correct 7 ms 604 KB Output is correct
61 Correct 7 ms 436 KB Output is correct
62 Correct 8 ms 596 KB Output is correct
63 Correct 8 ms 448 KB Output is correct
64 Correct 8 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 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 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 8 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 6 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 4 ms 600 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 10 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 8 ms 344 KB Output is correct
36 Correct 9 ms 344 KB Output is correct
37 Correct 5 ms 436 KB Output is correct
38 Correct 6 ms 432 KB Output is correct
39 Correct 8 ms 440 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 6 ms 444 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 5 ms 440 KB Output is correct
44 Correct 7 ms 604 KB Output is correct
45 Correct 5 ms 440 KB Output is correct
46 Correct 5 ms 600 KB Output is correct
47 Correct 5 ms 340 KB Output is correct
48 Correct 5 ms 344 KB Output is correct
49 Correct 5 ms 344 KB Output is correct
50 Correct 6 ms 600 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 7 ms 600 KB Output is correct
53 Correct 6 ms 344 KB Output is correct
54 Correct 7 ms 344 KB Output is correct
55 Correct 9 ms 344 KB Output is correct
56 Correct 5 ms 600 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 5 ms 600 KB Output is correct
59 Correct 6 ms 344 KB Output is correct
60 Correct 7 ms 344 KB Output is correct
61 Correct 6 ms 344 KB Output is correct
62 Correct 5 ms 700 KB Output is correct
63 Correct 5 ms 444 KB Output is correct
64 Correct 5 ms 688 KB Output is correct
65 Correct 7 ms 604 KB Output is correct
66 Correct 7 ms 856 KB Output is correct
67 Correct 8 ms 600 KB Output is correct
68 Correct 7 ms 444 KB Output is correct
69 Correct 8 ms 608 KB Output is correct
70 Correct 9 ms 856 KB Output is correct
71 Correct 7 ms 608 KB Output is correct
72 Correct 6 ms 696 KB Output is correct
73 Correct 7 ms 856 KB Output is correct
74 Correct 6 ms 444 KB Output is correct
75 Correct 6 ms 444 KB Output is correct
76 Correct 7 ms 856 KB Output is correct
77 Correct 6 ms 444 KB Output is correct
78 Correct 6 ms 952 KB Output is correct
79 Correct 7 ms 612 KB Output is correct
80 Correct 6 ms 696 KB Output is correct
81 Correct 7 ms 440 KB Output is correct
82 Correct 7 ms 852 KB Output is correct