結果

問題 No.326 あみだますたー
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-03 16:41:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,983 bytes
コンパイル時間 3,931 ms
コンパイル使用メモリ 81,164 KB
実行使用メモリ 49,512 KB
最終ジャッジ日時 2024-04-16 23:31:41
合計ジャッジ時間 15,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    System.out.println(Arrays.toString(process));
    getNewHori(vert, process, newLines1, true);
    System.out.println(Arrays.toString(process));

    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.add(newLine);
          }else{
            arrayList.push(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