結果
| 問題 |
No.1635 Let’s Sort Integers!!
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-11-18 20:31:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 102 ms / 2,000 ms |
| コード長 | 901 bytes |
| コンパイル時間 | 1,754 ms |
| コンパイル使用メモリ | 166,992 KB |
| 実行使用メモリ | 7,680 KB |
| 最終ジャッジ日時 | 2024-11-18 20:31:53 |
| 合計ジャッジ時間 | 18,317 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 77 |
ソースコード
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,a[1000005],up,down;
ll k;
ll calc(){
ll res=0;
for(int i=2;i<=n;i++)res+=abs(a[i]-a[i-1]);
return res;
}
void rev(int l,int r){
while(l<r)swap(a[l],a[r]),l++,r--;
}
int main(){
scanf("%d%lld",&n,&k);
int h=n-1;up=1,down=n;
if(h>k){
puts("-1");
return 0;
}
k-=h;int lt=n,tg=0;
for(int i=n-2;i;i--){
if(k>=i){
k-=i;
int u=i+1;
int L=n-lt+1,R=n-u;
if(!tg)for(int j=L;j<=R;j++)a[j]=up++;
else for(int j=L;j<=R;j++)a[j]=down--;
lt=i+1;
tg^=1;
}
}
int L=n-lt+1,R=n;
if(!tg)for(int j=L;j<=R;j++)a[j]=up++;
else for(int j=L;j<=R;j++)a[j]=down--;
if(k>0){
bool fl=0;
for(int i=1;i<n;i++){
if(abs(a[i+1]-a[i])+k==abs(a[i+1]-a[1])){
rev(1,i);
fl=1;
break;
}
}
if(!fl){
puts("-1");
return 0;
}
}
for(int i=1;i<=n;i++)printf("%d ",a[i]);
puts("");
return 0;
}
vjudge1