結果

問題 No.326 あみだますたー
ユーザー kenji_shioya
提出日時 2016-06-03 01:53:32
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 3,714 ms
コンパイル使用メモリ 80,888 KB
実行使用メモリ 61,980 KB
最終ジャッジ日時 2024-10-08 06:07:47
合計ジャッジ時間 15,823 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise51{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int vert = sc.nextInt();
    int hori = sc.nextInt();

    int[][] lines = new int[hori][2];

    for (int a = 0; a < hori; a++){
      lines[a][0] = sc.nextInt();
      lines[a][1] = sc.nextInt();
    }

    int[] answer = new int[vert];

    for (int b = 0; b < vert; b++){
      answer[b] = sc.nextInt();
    }

    ArrayList<int[]> newLines = new ArrayList<int[]>();

    for (int i = 0; i < vert; i++){
      int currentNum = i + 1;
      for (int j = 0; j < hori; j++){
        if (currentNum == lines[j][0]){
          currentNum++;
        }else if(currentNum == lines[j][1]){
          currentNum--;
        }
      }
      for (int k = 0; k < newLines.size(); k++){
        int[] newLine = new int[2];
        newLine = newLines.get(k);
        if (currentNum == newLine[0]){
          currentNum++;
        }else if(currentNum == newLine[1]){
          currentNum--;
        }
      }
      // public static int[] addNewLine(i, answer, currentNum, newLines)
      addNewLine(i, answer, currentNum, newLines);
    }

    System.out.println(newLines.size());
    for (int c = 0; c < newLines.size(); c++){
      int[] newLine = new int[2];
      newLine = newLines.get(c);
      System.out.println(newLine[0] + " " + newLine[1]);
    }
  }
  public static void addNewLine(int i, int[] answer, int currentNum, ArrayList<int[]> newLines){
    if (answer[i] == currentNum){
      return;
    } else if (answer[i] > currentNum){
      int[] newLine = new int[2];
      newLine[0] = currentNum;
      newLine[1] = currentNum + 1;
      currentNum++;
      newLines.add(newLine);
      addNewLine(i, answer, currentNum, newLines);
    } else if (answer[i] < currentNum){
      int[] newLine = new int[2];
      newLine[0] = currentNum - 1;
      newLine[1] = currentNum;
      currentNum--;
      newLines.add(newLine);
      addNewLine(i, answer, currentNum, newLines);
    }
  }
}
0