Submission #52604504
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
const INF int = math.MaxInt64
var (
sc *bufio.Scanner = initSc()
wr *bufio.Writer = initWr()
)
func main() {
defer wr.Flush()
// 標準入力を受け取る
ri()
as := ris()
res := solve(as)
out(len(res))
for _, v := range res {
outIS(v)
}
}
func solve(as []int) [][]int { // 受け取った入力を全て受け取り答えを出力
n := len(as)
res := make([][]int, 0, n)
for i := 0; i < n; i++ {
if as[i] == i+1 {
continue
}
idx := as[i] - 1
as[i], as[idx] = as[idx], as[i]
res = append(res, []int{i + 1, idx + 1})
i--
}
return res
}
// the followings are the template IO functions
func initSc() *bufio.Scanner {
sc := bufio.NewScanner(os.Stdin)
sc.Buffer([]byte{}, math.MaxInt64) // どでか入力対策
return sc
}
func initWr() *bufio.Writer {
return bufio.NewWriter(os.Stdout)
}
func ri() int {
sc.Scan()
return atoi(sc.Text())
}
func ri2() (int, int) {
sc.Scan()
ss := strings.Split(sc.Text(), " ")
return atoi(ss[0]), atoi(ss[1])
}
func ri3() (int, int, int) {
sc.Scan()
ss := strings.Split(sc.Text(), " ")
return atoi(ss[0]), atoi(ss[1]), atoi(ss[2])
}
func ris() []int {
sc.Scan()
ss := strings.Split(sc.Text(), " ")
is := make([]int, len(ss))
for i, s := range ss {
is[i] = atoi(s)
}
return is
}
func risn(n int) [][]int { // nは行数
sl := make([][]int, n)
for i := 0; i < n; i++ {
sl[i] = ris()
}
return sl
}
func rs() string {
sc.Scan()
return sc.Text()
}
func rss() []string {
sc.Scan()
return strings.Split(sc.Text(), " ")
}
func rssn(n int) [][]string {
sl := make([][]string, n)
for i := 0; i < n; i++ {
sl[i] = rss()
}
return sl
}
func rcs() []string { // 文字列を1文字ずつ受け取る
sc.Scan()
return strings.Split(sc.Text(), "")
}
func rcsn(n int) [][]string {
sl := make([][]string, n)
for i := 0; i < n; i++ {
sl[i] = rcs()
}
return sl
}
func out(v ...interface{}) {
_, err := fmt.Fprintln(wr, v...)
if err != nil {
panic(err)
}
}
func outIS(is []int) {
ss := make([]string, len(is))
for i, v := range is {
ss[i] = itoa(v)
}
out(strings.Join(ss, " "))
}
func outSS(ss []string) {
out(strings.Join(ss, " "))
}
// the followings are the slice functions
func del[T interface{}](a []T, i int) []T {
return a[:i+copy(a[i:], a[i+1:])]
}
func delR[T interface{}](a []T, i int) []T { // 順番を考慮せずに削除(遥かに高速)
a[i] = a[len(a)-1]
return a[:len(a)-1]
}
// the followings are the generic template functions
func atoi(s string) int {
i, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return i
}
func itoa(i int) string {
return strconv.Itoa(i)
}
func min(a int, b int) int {
if a >= b {
return b
} else {
return a
}
}
func max(a int, b int) int {
if a >= b {
return a
} else {
return b
}
}
func chMin(a *int, b int) bool {
tmp := *a
*a = min(*a, b)
if tmp == *a {
return false
} else {
return true
}
}
func chMax(a *int, b int) bool {
tmp := *a
*a = max(*a, b)
if tmp == *a {
return false
} else {
return true
}
}
func nmin(a []int) (int, int) {
if len(a) == 0 {
return -1, -1
}
idx, mini := 0, a[0]
for i, v := range a {
if chMin(&mini, v) {
idx = i
}
}
return idx, mini
}
func nmax(a []int) (int, int) {
if len(a) == 0 {
return -1, -1
}
idx, maxi := 0, a[0]
for i, v := range a {
if chMax(&maxi, v) {
idx = i
}
}
return idx, maxi
}
func nsum(a []int) int {
sum := 0
for _, v := range a {
sum += v
}
return sum
}
func ntime(a []int) int {
prod := 1
for _, v := range a {
prod *= v
}
return prod
}
func pow(a int, b int) int {
exp := 1
for i := 0; i < b; i++ {
exp *= a
}
return exp
}
func fact(n int) int {
res := 1
for i := 1; i <= n; i++ {
res *= i
}
return res
}
func abs(a int) int {
if a >= 0 {
return a
} else {
return -a
}
}
func gcd(a, b int) int {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func lcm(a, b int) int {
return a / gcd(a, b) * b
}
func nroot(n int, a int) int {
l, r := 0, a
var m int
for l+1 < r {
m = (l + r) / 2
if pow(m, n) > a {
r = m
} else {
l = m
}
}
return l
}
Submission Info
Submission Time |
|
Task |
C - Sort |
User |
mineel |
Language |
Go (go 1.20.6) |
Score |
300 |
Code Size |
4472 Byte |
Status |
AC |
Exec Time |
69 ms |
Memory |
22136 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name |
Status |
Exec Time |
Memory |
random_01.txt |
AC |
66 ms |
20440 KB |
random_02.txt |
AC |
62 ms |
22136 KB |
random_03.txt |
AC |
65 ms |
20308 KB |
random_04.txt |
AC |
6 ms |
4400 KB |
random_05.txt |
AC |
67 ms |
20568 KB |
random_06.txt |
AC |
43 ms |
16420 KB |
random_07.txt |
AC |
1 ms |
1568 KB |
random_08.txt |
AC |
1 ms |
1624 KB |
random_09.txt |
AC |
13 ms |
9876 KB |
random_10.txt |
AC |
8 ms |
7996 KB |
random_11.txt |
AC |
45 ms |
17528 KB |
random_12.txt |
AC |
14 ms |
7196 KB |
random_13.txt |
AC |
69 ms |
21184 KB |
random_14.txt |
AC |
21 ms |
8120 KB |
random_15.txt |
AC |
65 ms |
20408 KB |
random_16.txt |
AC |
44 ms |
16476 KB |
random_17.txt |
AC |
45 ms |
16720 KB |
random_18.txt |
AC |
4 ms |
3356 KB |
random_19.txt |
AC |
46 ms |
16748 KB |
random_20.txt |
AC |
13 ms |
6380 KB |
sample_01.txt |
AC |
1 ms |
1572 KB |
sample_02.txt |
AC |
1 ms |
1608 KB |
sample_03.txt |
AC |
1 ms |
1620 KB |