結果
| 問題 | 
                            No.370 道路の掃除
                             | 
                    
| コンテスト | |
| ユーザー | 
                             fjafjafja
                         | 
                    
| 提出日時 | 2017-09-12 21:27:46 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,498 bytes | 
| コンパイル時間 | 4,217 ms | 
| コンパイル使用メモリ | 79,768 KB | 
| 実行使用メモリ | 47,316 KB | 
| 最終ジャッジ日時 | 2024-11-07 17:25:52 | 
| 合計ジャッジ時間 | 9,460 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 TLE * 1 -- * 22 | 
ソースコード
package yukicoder;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class N370
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner (System.in);
		int N=sc.nextInt(),M=sc.nextInt();
		Integer[] d=new Integer[M];
		Integer[] pbuf=new Integer[M];
		Integer[] nbuf=new Integer[M];
		for(int i=0;i<M;i++)
		{
			pbuf[i]=10001;
			nbuf[i]=-10001;
		}
		int pos=0,neg=0;
		for(int i=0;i<M;i++)
		{
			d[i]=sc.nextInt();
			if(d[i]==0){N--;}
			if(d[i]>0){pbuf[pos++]=d[i];}
			if(d[i]<0){nbuf[neg++]=d[i];}
		}
		Arrays.sort(d);
		Arrays.sort(pbuf,Comparator.naturalOrder());
		Arrays.sort(nbuf,Comparator.reverseOrder());
		Integer[] Ph=new Integer[N];
		for(int i=0;i<N;i++){Ph[i]=pbuf[i];}
		Integer[] Nh=new Integer[N];
		for(int i=0;i<N;i++){Nh[i]=nbuf[i];}
		int pp=0;
		int np=0;
		int now=0;
		int end=0;
		int ans=0;
		int min=Integer.MAX_VALUE;
		for(int i=0;i<(int)Math.pow(2,N);i++)
		{
			now=0;
			ans=0;
			pp=0;
			np=0;
			end=0;
			for(int j=0;j<N;j++)
			{
				if(end==1){break;}
				if((i&(int)Math.pow(2,j))!=0) 
				{
					if(Ph[pp]==10001)
					{
						end++;
					}
					else
					{
						ans+=((int)Math.abs(Ph[pp]-now));
						now=Ph[pp];
						pp++;
					}
				}
				else
				{
					if(Nh[np]==-10001)
					{
						end++;
					}
					else
					{
						ans+=((int)Math.abs(Nh[np]-now));
						now=Nh[np];
						np++;
					}
				}
			}
			if(end!=1&&min>ans){min=ans;}
			
		}
		System.out.println(min);
	}
}
            
            
            
        
            
fjafjafja