結果
| 問題 |
No.326 あみだますたー
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2015-12-23 03:15:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,592 bytes |
| コンパイル時間 | 1,101 ms |
| コンパイル使用メモリ | 108,928 KB |
| 実行使用メモリ | 20,352 KB |
| 最終ジャッジ日時 | 2024-11-07 23:24:13 |
| 合計ジャッジ時間 | 3,463 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
int[] B=new int[N];
for(int i=0;i<N;i++){
B[A[i]-1]=i+1;
}
//Console.WriteLine(String.Join(" ",B));
int[] C=Enumerable.Range(1,N).ToArray();
for(int i=0;i<K;i++){
int tmp=C[X[i]-1];C[X[i]-1]=C[Y[i]-1];C[Y[i]-1]=tmp;
}
//Console.WriteLine(String.Join(" ",C));
List<int> XX=new List<int>();
for(int i=0;i<N;i++){
if(C[i]==B[i])continue;
int j=i;
while(C[j]!=B[i])j++;
j--;
while(j>=i){
XX.Add(j+1);
var tt=C[j];C[j]=C[j+1];C[j+1]=tt;
j--;
}
}
Console.WriteLine(XX.Count);
foreach(var x in XX)Console.WriteLine("{0} {1}",x,x+1);
}
int N,K;
int[] X,Y;
int[] A;
public Sol(){
N=ri();
K=ri();
X=new int[K];
Y=new int[K];
for(int i=0;i<K;i++){
var d=ria();
X[i]=d[0];
Y[i]=d[1];
}
A=ria();
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
kuuso1