結果

問題 No.326 あみだますたー
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-03 01:53:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 3,859 ms
コンパイル使用メモリ 79,752 KB
実行使用メモリ 49,184 KB
最終ジャッジ日時 2024-04-16 23:25:53
合計ジャッジ時間 16,749 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,580 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 144 ms
41,408 KB
testcase_06 AC 341 ms
48,620 KB
testcase_07 AC 221 ms
44,496 KB
testcase_08 AC 313 ms
46,868 KB
testcase_09 AC 421 ms
48,980 KB
testcase_10 AC 415 ms
48,880 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 287 ms
48,296 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 166 ms
42,176 KB
testcase_21 AC 165 ms
42,468 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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