結果

問題 No.1635 Let’s Sort Integers!!
ユーザー publflpublfl
提出日時 2021-07-30 22:37:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 631 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-09-16 01:30:26
合計ジャッジ時間 11,818 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int a;
long long int b;
int ans[1000010];
void func(int k, int type, int L, int R)
{
	if(k>a) return;
	if(type==1)
	{
		if(R-L+1 + R-L <= b)
		{
			b -= (R-L+1);
			ans[k] = R;
			func(k+1,2,L,R-1);
		}
		else
		{
			b--;
			ans[k] = L;
			func(k+1,1,L+1,R);
		}
	}
	else
	{
		if(R-L+1 + R-L <= b)
		{
			b -= (R-L+1);
			ans[k] = L;
			func(k+1,1,L+1,R);
		}
		else
		{
			b--;
			ans[k] = R;
			func(k+1,2,L,R-1);
		}
	}
}

int main()
{
	scanf("%d%lld",&a,&b);
	if(b<a-1)
	{
		printf("-1");
		return 0;
	}
	ans[1] = 1;
	func(2,1,2,a);
	if(b>0) printf("-1");
	else for(int i=1;i<=a;i++) printf("%d ",ans[i]);
}
0