Submission #2668041


Source Code Expand

///
// File:  a.go
// Author: ymiyamoto
//
// Created on Thu Jun 14 23:23:31 2018
//
package main

import (
	"fmt"
	"sort"
)

const MOD int = 1e9 + 7

var N int
var a, b []int

func main() {
	fmt.Scan(&N)
	a = make([]int, N)
	b = make([]int, N)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range b {
		fmt.Scan(&b[i])
	}
	sort.Ints(a)
	sort.Ints(b)

	ans := 1
	seta := make([]int, 0)
	setb := make([]int, 0)
	indexa := 0
	indexb := 0
	for i := 0; i < 2*N; i++ {
		if indexb >= len(b) || (indexa < len(a) && a[indexa] < b[indexb]) {
			if len(setb) > 0 {
				ans *= len(setb)
				ans %= MOD
				setb = setb[1:]
			} else {
				seta = append(seta, a[indexa])
			}
			indexa++
		} else {
			if len(seta) > 0 {
				ans *= len(seta)
				ans %= MOD
				seta = seta[1:]
			} else {
				setb = append(setb, b[indexb])
			}
			indexb++
		}
	}
	fmt.Println(ans)
}

Submission Info

Submission Time
Task A - 1D Matching
User mohei
Language Go (1.6)
Score 500
Code Size 919 Byte
Status AC
Exec Time 1377 ms
Memory 7040 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 14
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 832 ms 5504 KB
001.txt AC 300 ms 4224 KB
002.txt AC 422 ms 5504 KB
003.txt AC 470 ms 5504 KB
004.txt AC 1231 ms 6656 KB
005.txt AC 1367 ms 5504 KB
006.txt AC 1366 ms 5504 KB
007.txt AC 1373 ms 5504 KB
008.txt AC 1371 ms 5504 KB
009.txt AC 1377 ms 5504 KB
010.txt AC 1370 ms 7040 KB
011.txt AC 1372 ms 5504 KB
example0.txt AC 1 ms 512 KB
example1.txt AC 1 ms 512 KB