Submission #3377623


Source Code Expand

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    long[][] nums = new long[2*n][];//座標と種類
    long memo = 0;
    long multiplyMemo = 1;
    long answer = 1;
    long mod = 1000000007;
    for(long i = 0; i < n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 0;
    }
    for(long i = n; i < 2*n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 1;
    }
    Array.Sort(nums, (a, b) => a[0].CompareTo(b[0]));
    for(long i = 0; i < 2*n; i++)
    {
      if(nums[i][1] == 0)
      {
        memo++;
        if(memo < -1) multiplyMemo *= DivideModReverse(-memo, mod);
        multiplyMemo %= mod;
        if(memo > 1)
        {
          multiplyMemo *= Math.Abs(memo)-1;
          multiplyMemo %= mod;
          answer += multiplyMemo*(Math.Abs(memo)-1);
        }
        answer %= mod;
      }
      else
      {
        memo--;
        if(memo > 1) multiplyMemo *= DivideModReverse(memo, mod);
        multiplyMemo %= mod;
        if(memo < -1)
        {
          multiplyMemo *= Math.Abs(memo)-1;
          multiplyMemo %= mod;
          answer += multiplyMemo*(Math.Abs(memo)-1);
        }
        answer %= mod;
      }
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)
  {
  long num = 2;
  long answer = 1;
  long check = a;
  long memo = x%p;
  
  while(check > 0)
    {
    if(check % num == num / 2)
      {
      check -= num / 2;
      answer *= memo;
      answer %= p;
      }
  memo *= memo;
  memo %= p;
  num *= 2;
    }
  return answer;
  }

static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数
  {
  long answer = DivideMod(x, p-2, p);
  return answer;
  }
  
}

Submission Info

Submission Time
Task A - 1D Matching
User suikameron
Language C# (Mono 4.6.2.0)
Score 0
Code Size 2124 Byte
Status WA
Exec Time 333 ms
Memory 29520 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 4
WA × 10
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 WA 199 ms 18392 KB
001.txt WA 81 ms 13408 KB
002.txt WA 109 ms 17756 KB
003.txt WA 120 ms 17884 KB
004.txt WA 283 ms 20948 KB
005.txt WA 322 ms 23504 KB
006.txt WA 333 ms 23504 KB
007.txt WA 319 ms 27472 KB
008.txt WA 321 ms 23504 KB
009.txt WA 319 ms 23504 KB
010.txt AC 316 ms 27472 KB
011.txt AC 215 ms 29520 KB
example0.txt AC 22 ms 11220 KB
example1.txt AC 22 ms 11220 KB