AtCoder Grand Contest 006 B - Median Pyramid Easy
- 問題
- 解法
実際にピラミッドを作るにはの時間計算量がかかるため無理。なので入力から直接数列を作ることを考えないといけない。
のときは無理である(中央値になりえないため)。のときはを出力すれば良い。他の場合は解説pdfにある通りで2段目の真ん中の2マスがになればよい。このようにするには、のときは数列の真ん中にを、その隣にを配置すれば良い。のときは数列の真ん中に、その隣にを配置すれば良い。
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <vector> #include <cmath> using namespace std; typedef long long int ll; #define all(x) x.begin(),x.end() const ll mod = 1e9+7; const ll INF = 1e9; const ll MAXN = 1e9; int main() { int n,x; cin >> n >> x; if(x == 1 || x == 2*n-1) cout << "No" << endl; else{ cout << "Yes" << endl; vector<int> ans(2*n); for(int i = 0; i < ans.size(); i++){ ans[i] = i; } if(x != n){ if(x < n){ ans[n-1] = x; ans[x] = n-1; ans[n] = 1; ans[1] = n; }else{ ans[n+1] = x; ans[x] = n+1; ans[2*n-1] = n; ans[n] = 2*n-1; } } for(int i = 1; i <= 2*n-1; i++){ cout << ans[i] << endl; } } return 0; }