結果

問題 No.326 あみだますたー
ユーザー kenji_shioya
提出日時 2016-06-03 16:52:56
言語 Java
(openjdk 23)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 1,883 bytes
コンパイル時間 3,982 ms
コンパイル使用メモリ 84,072 KB
実行使用メモリ 49,088 KB
最終ジャッジ日時 2024-11-08 00:20:34
合計ジャッジ時間 13,229 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise53{
  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();
    }

    LinkedList<int[]> newLines1 = new LinkedList<int[]>();
    LinkedList<int[]> newLines2 = new LinkedList<int[]>();

    int[] process = new int[vert];

    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--;
        }
      }
      process[i] = currentNum;
    }
    getNewHori(vert, process, newLines1, true);

    getNewHori(vert, answer, newLines2, false);



    System.out.println(newLines1.size() + newLines2.size());
    showLines(newLines1);
    showLines(newLines2);

  }

  private static void getNewHori(int vert, int[] array, LinkedList<int[]> arrayList, boolean flag){
    for (int k = 0; k < vert - 1; k++){
      for (int i = vert - 1; i > k; i--){
        if (array[i] < array[i - 1]){
          int w = array[i];
          array[i] = array[i - 1];
          array[i - 1] = w;
          int[] newLine = new int[2];
          newLine[0] = i;
          newLine[1] = i + 1;
          if (flag){
            arrayList.push(newLine);
          }else{
            arrayList.add(newLine);
          }
        }
      }
    }
  }

  private static void showLines(LinkedList<int[]> arrayList){
    for (int i = 0; i < arrayList.size(); i++){
      int[] line = arrayList.get(i);
      System.out.println(line[0] + " " + line[1]);
    }
  }
}
0