fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Global Round 29-B (Div. 1 + Div. 2) Multiple Construction
최초 업로드: 2025-09-21 05:57:32
최근 수정 시간: 2025-09-21 05:57:32
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 7
# B. Multiple Construction [문제 링크](https://codeforces.com/contest/2147/problem/B) ## Problem Statement You are given an integer $n$. Your task is to construct an array of length $2 \cdot n$ such that: - Each integer from $1$ to $n$ appears exactly twice in the array. - For each integer $x$ ($1 \le x \le n$), the distance between the two occurrences of $x$ is a multiple of $x$. In other words, if $p_x$ and $q_x$ are the indices of the two occurrences of $x$, then $\lvert q_x - p_x \rvert$ must be divisible by $x$. It can be shown that a solution always exists. ## Input Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. Each of the next $t$ lines contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^{5}$. ## Output For each test case, print a line containing $2 \cdot n$ integers — the array that satisfies the given conditions. If there are multiple valid answers, print any of them. ## 풀이 N N-1 ... 2 1 N 1 2 3 ... N-2 N-1 순서로 배치하면 된다. prof. N과 N 사이의 거리는 N이고, N이 아닌 다른 임의의 수 i 사이의 거리는 앞쪽 절반 중 자신보다 작은 i-1부터 1까지 총 i-1개 + 뒤쪽 절반의 첫 수 N 1개 + 뒤쪽 절반의 1부터 i까지 총 i개로 2i로 고정된다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int n; cin >> n; for(int i=n;i>=1;i--) cout << i << ' '; cout << n << ' '; for(int i=1;i<n;i++) cout << i << ' '; cout << '\n'; } } ```