結果
問題 | No.326 あみだますたー |
ユーザー | threepipes_s |
提出日時 | 2015-12-19 00:27:03 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 252 ms / 2,000 ms |
コード長 | 3,287 bytes |
コンパイル時間 | 3,463 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 58,408 KB |
最終ジャッジ日時 | 2023-08-07 18:21:58 |
合計ジャッジ時間 | 8,057 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,436 KB |
testcase_01 | AC | 72 ms
50,812 KB |
testcase_02 | AC | 122 ms
54,152 KB |
testcase_03 | AC | 227 ms
58,104 KB |
testcase_04 | AC | 152 ms
54,312 KB |
testcase_05 | AC | 44 ms
49,440 KB |
testcase_06 | AC | 181 ms
57,224 KB |
testcase_07 | AC | 78 ms
50,452 KB |
testcase_08 | AC | 190 ms
54,700 KB |
testcase_09 | AC | 243 ms
58,408 KB |
testcase_10 | AC | 252 ms
57,916 KB |
testcase_11 | AC | 93 ms
53,440 KB |
testcase_12 | AC | 183 ms
54,888 KB |
testcase_13 | AC | 218 ms
57,952 KB |
testcase_14 | AC | 126 ms
54,056 KB |
testcase_15 | AC | 136 ms
54,288 KB |
testcase_16 | AC | 163 ms
55,496 KB |
testcase_17 | AC | 153 ms
56,332 KB |
testcase_18 | AC | 141 ms
53,948 KB |
testcase_19 | AC | 182 ms
55,504 KB |
testcase_20 | AC | 75 ms
51,016 KB |
testcase_21 | AC | 75 ms
50,868 KB |
testcase_22 | AC | 184 ms
56,700 KB |
testcase_23 | AC | 185 ms
55,140 KB |
testcase_24 | AC | 232 ms
57,924 KB |
testcase_25 | AC | 225 ms
57,984 KB |
testcase_26 | AC | 104 ms
53,836 KB |
testcase_27 | AC | 209 ms
56,212 KB |
ソースコード
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Main { public static void main(String[] args) throws NumberFormatException, IOException {Solve solve = new Solve();solve.solve();} } class Solve{ void dump(int[]a){for(int i=0;i<a.length;i++) System.out.print(a[i]+" ");System.out.println();}; void solve() throws NumberFormatException, IOException{ final ContestScanner in = new ContestScanner(); Writer out = new Writer(); int n = in.nextInt(); int k = in.nextInt(); int[] a = new int[n]; for(int i=0; i<n; i++){ a[i] = i; } for(int i=0; i<k; i++){ int x = in.nextInt()-1; int y = in.nextInt()-1; int tmp = a[x]; a[x] = a[y]; a[y] = tmp; } int[] map = new int[n]; for(int i=0; i<n; i++){ map[a[i]] = i; } List<String> list = new ArrayList<>(); int[] b = new int[n]; for(int i=0; i<n; i++){ b[in.nextInt()-1] = i; } for(int i=0; i<n; i++){ for(int j=map[b[i]]; j>i; j--){ list.add((j)+" "+(j+1)); map[a[j]]--; map[a[j-1]]++; int tmp = a[j-1]; a[j-1] = a[j]; a[j] = tmp; } } System.out.println(list.size()); for(String s: list) System.out.println(s); } } class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key){ final int num = get(key); if(num==1) remove(key); else put(key, num-1); } } class Timer{ long time; public void set(){time = System.currentTimeMillis();} public long stop(){return System.currentTimeMillis()-time;} } class Writer extends PrintWriter{ public Writer(String filename) throws IOException {super(new BufferedWriter(new FileWriter(filename)));} public Writer() throws IOException{super(System.out);} } class ContestScanner { private BufferedReader reader; private String[] line; private int idx; public ContestScanner() throws FileNotFoundException {reader = new BufferedReader(new InputStreamReader(System.in));} public ContestScanner(String filename) throws FileNotFoundException {reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));} public String nextToken() throws IOException { if (line == null || line.length <= idx) { line = reader.readLine().trim().split(" "); idx = 0; } return line[idx++]; } public String readLine() throws IOException{return reader.readLine();} public long nextLong() throws IOException, NumberFormatException {return Long.parseLong(nextToken());} public int nextInt() throws NumberFormatException, IOException {return (int) nextLong();} public double nextDouble() throws NumberFormatException, IOException {return Double.parseDouble(nextToken());} }