結果
| 問題 | 
                            No.643 Two Operations No.2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             uafr_cs
                         | 
                    
| 提出日時 | 2018-02-02 21:48:00 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,277 bytes | 
| コンパイル時間 | 2,576 ms | 
| コンパイル使用メモリ | 78,272 KB | 
| 実行使用メモリ | 54,668 KB | 
| 最終ジャッジ日時 | 2024-12-31 07:24:22 | 
| 合計ジャッジ時間 | 5,428 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 6 WA * 7 | 
ソースコード
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
	
	public static int solve(int X, int Y){
		if(X == Y){ 
			return 0;
		}else if(Y == 0){
			// (X, 0) -> (X, X)
			return 1;
		}else if(X == 0){
			// (0, Y) -> (Y, 0)
			return 1 + solve(Y, 0);
		}else if(Math.abs(X) != Math.abs(Y)){
			return -1;
		}else{
			return solve(X + Y, X - Y);
		}
	}
	
	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int X = sc.nextInt();
		final int Y = sc.nextInt();
		
		int[][] DP = new int[100 + 1 + 100][100 + 1 + 100];
		for(int i = 0; i <= 200; i++){
			for(int j = 0; j <= 200; j++){
				DP[i][j] = (i == j) ? 0 : INF;
			}
		}
		
		while(true){
			boolean update = false;
			
			for(int i = 0; i <= 200; i++){
				for(int j = 0; j <= 200; j++){
					if(DP[j][i] > DP[i][j] + 1){
						DP[j][i] = DP[i][j] + 1; update = true;
					}
					if(j - i >= 0 && j + i <= 200 && DP[j - i][j + i] > DP[i][j] + 1){
						DP[j - i][j + i] = DP[i][j] + 1; update = true;
					}
				}
			}
			
			if(!update){ break; }
		}
		
		//System.out.println(solve(X, Y));
		System.out.println(DP[Y + 100][X + 100] == INF ? -1 : DP[Y + 100][X + 100]);
	}
}
            
            
            
        
            
uafr_cs