結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-21 12:06:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,788 bytes |
| コンパイル時間 | 4,188 ms |
| コンパイル使用メモリ | 80,840 KB |
| 実行使用メモリ | 89,424 KB |
| 最終ジャッジ日時 | 2024-10-13 10:29:26 |
| 合計ジャッジ時間 | 11,649 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 61 |
ソースコード
import java.util.*;
public class New {
private static final Value used=new Value(-1,-1);
public static void main(String[] args) {
int offset=0;
Scanner sc=new Scanner(System.in);
int len=sc.nextInt();
Value[] unsorted=new Value[len];
Value[] sorted=new Value[len];
for(int i=0;i<len;i++){
int read=sc.nextInt();
Value value=new Value(read,i);
unsorted[i]=value;
sorted[read-1]=value;
}
sorted[unsorted[len-1].value-1]=used;
int[] result=new int[len];
for(int i=0,filled=0;filled<len;filled+=2){
i=findMin(sorted,i);
Value value=sorted[i];
int next=findNext(unsorted,value.offset);
result[offset++]=value.value;
result[offset++]=unsorted[next].value;
remove(sorted,unsorted,value);
remove(sorted,unsorted,unsorted[next]);
}
StringBuilder builder=new StringBuilder(len*4);
for(Integer c:result){
builder.append(c).append(" ");
}
System.out.println(builder.toString().replaceFirst(" $",""));
}
private static int findMin(Value[] sortedArr,int start){
for(int i=start;i<sortedArr.length;i++){
if(sortedArr[i]!=used) return i;
}
throw new RuntimeException();
}
private static int findNext(Value[] unsorted,int start){
for(int i=start+1;i<unsorted.length;i++){
if(unsorted[i]!=used) return i;
}
throw new RuntimeException();
}
private static void remove(Value[] sorted,Value[] unsorted,Value v){
sorted[v.value-1]=used;
unsorted[v.offset]=used;
}
private record Value(int value,int offset){}
}