답안 #900531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900531 2024-01-08T12:49:18 Z abcvuitunggio 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
191 ms 760 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector <int> longest_trip(int N, int D){
    if (D>1){
        deque <int> q={0};
        if (!are_connected({0},{1}))
            q.push_back(2);
        q.push_back(1);
        for (int i=q.size();i<N;i++)
            if (are_connected({i},{q.front()}))
                q.push_front(i);
            else
                q.push_back(i);
        vector <int> res;
        for (int i:q)
            res.push_back(i);
        return res;
    }
    vector <int> a,b;
    a.push_back(0);
    b.push_back(1);
    for (int i=2;i<N;i++){
        if (are_connected({a.back()},{i})){
            a.push_back(i);
            continue;
        }
        if (are_connected({b.back()},{i})){
            b.push_back(i);
            continue;
        }
        reverse(b.begin(),b.end());
        for (int i:b)
            a.push_back(i);
        b={i};
    }
    if (a.size()<b.size())
        swap(a,b);
    for (int i=0;i<a.size();i+=a.size()-1)
        for (int j=0;j<b.size();j+=b.size()-1)
            if (are_connected({a[i]},{b[j]})){
                if (!i)
                    reverse(a.begin(),a.end());
                if (j)
                    reverse(b.begin(),b.end());
                for (int k:b)
                    a.push_back(k);
                return a;
            }
    for (int i=0;i<b.size();i++)
        if (are_connected(a,{b[i]})){
            for (int j=0;j<a.size();j++)
                if (are_connected({a[j]},{b[i]})){
                    vector <int> c;
                    for (int k=(j+1)%a.size();c.size()<a.size();k=(k+1)%a.size())
                        c.push_back(a[k]);
                    for (int k=i;c.size()<a.size()+b.size();k=(k+1)%b.size())
                        c.push_back(b[k]);
                    return c;
                }
        }
    return a;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i=0;i<a.size();i+=a.size()-1)
      |                  ~^~~~~~~~~
longesttrip.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j=0;j<b.size();j+=b.size()-1)
      |                      ~^~~~~~~~~
longesttrip.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i=0;i<b.size();i++)
      |                  ~^~~~~~~~~
longesttrip.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for (int j=0;j<a.size();j++)
      |                          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 760 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 340 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 5 ms 600 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 436 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 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Incorrect 178 ms 344 KB too many calls
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 356 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 344 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Incorrect 191 ms 344 KB too many calls
7 Halted 0 ms 0 KB -