Submission #3285638


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            var ps = new List<int>();
            var cs = new List<int>();
            for (int i = 0; i < N; i++)
            {
                ps.Add(Input.ReadInt());
            }

            for (int i = 0; i < N; i++)
            {
                cs.Add(Input.ReadInt());
            }

            ps.Sort();
            cs.Sort();

            var pi = 0;
            var ci = 0;
            int p = 0;
            int c = 0;
            long ret = 1;

            while (true)
            {
                if (ci == N || (pi != N && ps[pi] < cs[ci]))
                {
                    pi++;
                    p++;
                }
                else
                {
                    ci++;
                    c++;
                }

                if (c > 0 && p > 0)
                {
                    ret *= (c * p);
                    ret %= MOD;
                    c--;
                    p--;
                }

                if (pi == N && ci == N) break;
            }

            Console.WriteLine(ret);
        }
    }
    
    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Submission Info

Submission Time
Task A - 1D Matching
User threecourse
Language C# (Mono 4.6.2.0)
Score 500
Code Size 2656 Byte
Status AC
Exec Time 143 ms
Memory 17116 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 94 ms 16096 KB
001.txt AC 46 ms 11488 KB
002.txt AC 57 ms 11488 KB
003.txt AC 62 ms 14048 KB
004.txt AC 129 ms 17116 KB
005.txt AC 142 ms 15068 KB
006.txt AC 143 ms 15068 KB
007.txt AC 143 ms 15068 KB
008.txt AC 143 ms 15068 KB
009.txt AC 143 ms 15068 KB
010.txt AC 142 ms 17116 KB
011.txt AC 142 ms 15068 KB
example0.txt AC 21 ms 11220 KB
example1.txt AC 20 ms 9172 KB