답안 #1042467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042467 2024-08-03T04:45:17 Z kwongweng 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
8 ms 456 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef vector<vector<ll>> vll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define ms memset
#define fi first
#define se second

vi longest_trip(int N, int D)
{
    vector<vi> CC;
    FOR(i,0,N) CC.pb({i});
    while (CC.size() > 2){
        int sz = CC.size();
        if (are_connected({CC[sz-1][0]}, {CC[0][CC[0].size()-1]})){
            FOR(i,0,CC[sz-1].size()){
                CC[0].pb(CC[sz-1][i]);
            }
            CC.pop_back(); continue;
        }
        if (are_connected({CC[sz-1][0]}, {CC[1][CC[1].size()-1]})){
            FOR(i,0,CC[sz-1].size()){
                CC[1].pb(CC[sz-1][i]);
            }
            CC.pop_back(); continue;
        }
        ROF(i,CC[1].size()-1,0){
            CC[0].pb(CC[1][i]);
        }
        FOR(i,1,sz-1){
            CC[i]=CC[i+1];
        }
        CC.pop_back();
    }
    int s0 = CC[0].size(), s1 = CC[1].size();
    if (are_connected(CC[0], CC[1])){
        if (are_connected({CC[0][0]}, {CC[1][0]})){
            reverse(CC[0].begin(), CC[0].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][0]}, {CC[1][s1-1]})){
            reverse(CC[0].begin(), CC[0].end());
            reverse(CC[1].begin(), CC[1].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][s0-1]}, {CC[1][0]})){
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        if (are_connected({CC[0][s0-1]}, {CC[1][s1-1]})){
            reverse(CC[1].begin(), CC[1].end());
            FOR(i,0,s1) CC[0].pb(CC[1][i]);
            return CC[0];
        }
        FOR(i,0,s0){
            FOR(j,0,s1){
                if (are_connected({CC[0][i]},{CC[1][j]})){
                    vi ans;
                    FOR(k,i+1,i+s0+1) ans.pb(CC[0][k%s0]);
                    FOR(k,j,j+s1) ans.pb(CC[0][k%s1]);
                    return ans;
                }
            }
        }
        int l = 0, r = s0;
        while (r-l>1){
            int mid = (l+r)/2;
            vi A; FOR(i,0,mid) A.pb(CC[0][i]);
            if (are_connected(A, CC[1])){
                r = mid;
            }else{
                l = mid;
            }
        }
        int a = r; l=0; r=s1;
        while (r-l>1){
            int mid = (l+r)/2;
            vi A; FOR(i,0,mid) A.pb(CC[1][i]);
            if (are_connected({a}, A)){
                r=mid;
            }else{
                l=mid;
            }
        }
        vi ans;
        FOR(i,a+1,a+s0+1) ans.pb(CC[0][i%s0]);
        FOR(i,r,r+s1) ans.pb(CC[1][i%s1]);
        return ans;
    }
    if (CC[0].size()>CC[1].size()) return CC[0];
    return CC[1];
}

Compilation message

longesttrip.cpp: In function 'vi longest_trip(int, int)':
longesttrip.cpp:10:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
   24 |             FOR(i,0,CC[sz-1].size()){
      |                 ~~~~~~~~~~~~~~~~~~~    
longesttrip.cpp:24:13: note: in expansion of macro 'FOR'
   24 |             FOR(i,0,CC[sz-1].size()){
      |             ^~~
longesttrip.cpp:10:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
   30 |             FOR(i,0,CC[sz-1].size()){
      |                 ~~~~~~~~~~~~~~~~~~~    
longesttrip.cpp:30:13: note: in expansion of macro 'FOR'
   30 |             FOR(i,0,CC[sz-1].size()){
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 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 6 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 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 7 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 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 4 ms 344 KB Output is correct
10 Correct 6 ms 456 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 4 ms 448 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 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 6 ms 344 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 6 ms 432 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 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -