結果
| 問題 | 
                            No.496 ワープクリスタル (給料日前編)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yun_app
                         | 
                    
| 提出日時 | 2017-03-28 17:08:37 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,029 bytes | 
| コンパイル時間 | 1,971 ms | 
| コンパイル使用メモリ | 78,236 KB | 
| 実行使用メモリ | 76,728 KB | 
| 最終ジャッジ日時 | 2024-07-06 13:22:55 | 
| 合計ジャッジ時間 | 6,914 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 3 WA * 1 TLE * 1 -- * 18 | 
ソースコード
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int gx = Integer.parseInt(lines[0]);
        int gy = Integer.parseInt(lines[1]);
        int n  = Integer.parseInt(lines[2]);
        int f  = Integer.parseInt(lines[3]);
        
        Place start = new Place(0,0);
        Place goal = new Place(gx,gy);
        ArrayList<Crystal> crystals = new ArrayList<Crystal>();
        for(int i=0;i<n;i++){
            crystals.add(new Crystal(i,br.readLine()));
        }
        
        PriorityQueue<Place> queue = new PriorityQueue<Place>(1, new Comparator<Place>(){
            public int compare(Place p1,Place p2){
                return p1.c-p2.c;
            }
        });
        queue.add(start);
        while(!queue.isEmpty()){
            Place now = queue.poll();
            if(now.x == goal.x && now.y == goal.y){
                goal = now;
                break;
            }
            for(Crystal c:crystals){
                if(now.canUseCrystal(c)){
                    Place newPlace = now.clone();
                    newPlace.useCrystal(c);
                    queue.add(newPlace);
                }
            }
            Place newPlace = now.clone();
            newPlace.move(goal,f);
            queue.add(newPlace);
        }
        System.out.println(goal.c);
    }
    private static class Place{
        int x,y;
        int c;
        ArrayList<Integer> useCrystal = new ArrayList<Integer>();
        
        public Place(int x,int y){
            this.x = x;
            this.y = y;
            this.c = 0;
        }
        public Place clone(){
            Place p = new Place(this.x,this.y);
            p.c = this.c;
            for(int n:this.useCrystal){
                p.useCrystal.add(n);
            }
            return p;
        }
        public boolean canUseCrystal(Crystal c){
            return useCrystal.indexOf(c.no)==-1;
        }
        public void useCrystal(Crystal c){
            this.x += c.x;
            this.y += c.y;
            this.c += c.c;
            useCrystal.add(c.no);
        }
        public void move(Place g,int f){
            int cost = f*(g.x-this.x);
            cost += f*(g.y-this.y);
            this.x = g.x;
            this.y = g.y;
            this.c += cost;
        }
    }
    private static class Crystal{
        public int no;
        public int x,y,c;
        public Crystal(int no,String line){
            this.no = no;
            String[] lines = line.split(" ");
            this.x = Integer.parseInt(lines[0]);
            this.y = Integer.parseInt(lines[1]);
            this.c = Integer.parseInt(lines[2]);
        }
    }
}
            
            
            
        
            
yun_app