Submission #1385918


Source Code Expand

import std.algorithm;
import std.array;
import std.conv;
import std.format;
import std.math;
import std.stdio;
import std.string;
 
ulong[][] choose(long n, long r)
{
  ulong[][] dp = new ulong[][](n+1, r+1);
 
  int i,j = 0;
  for (i=0;i<n;i++) {
    dp[i][0] = 1;
  }
  for (j=0;j<r;j++) {
    dp[0][j] = 0;
  }
  for (i=1;i<=n;i++) {
    for (j=1;j<=r;j++) {
      if (i==j) {
        dp[i][j] = 1;
      } else if (j>i) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
        //writefln("nCr (n = %d, r = %d) = %d", i, j, dp[i][j]);
      }
    }
  }
 
  return dp;
}
 
immutable long MOD = 10^^9+7;
 
void main()
{
  string lines;
  string buf;
  while (!stdin.eof) {
    buf = stdin.readln();
    lines ~= buf;
  }
  string[] array = splitLines(lines);
 
  immutable long N = array[0].to!long;
  array = array[1..$];
 
  immutable long[] a = array.map!(e => e.split(" ")[0].to!long).array;
  immutable long[] b = array.map!(e => e.split(" ")[1].to!long).array;
  const dp = choose(2000, 2000);
 
  ulong ans = 0;
 
  for (int i = 0; i < a.length; i++) {
    long ai = a[i] + b[i];
    for (int j = 0; j < a.length; j++) {
      long n = ai + a[j] + b[j];
      long r = b[i] + b[j];
      //writefln("nCr (n = %d, r = %d) = %d", n, r, dp[n][r]);
      ans += dp[n][r];
      //writefln("ans -> %d", ans);
    }
    ans -= dp[2*ai][2*b[i]];
  }
 
  writeln( (ans / 2) % MOD );
}

Submission Info

Submission Time
Task E - BBQ Hard
User hiroyuking
Language D (GDC 4.9.4)
Score 0
Code Size 1489 Byte
Status RE
Exec Time 2104 ms
Memory 43900 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 1
AC × 3
TLE × 2
RE × 11
Set Name Test Cases
Sample sample-01.txt
All sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, sample-01.txt
Case Name Status Exec Time Memory
01-01.txt RE 130 ms 33660 KB
01-02.txt RE 113 ms 33660 KB
01-03.txt RE 195 ms 37500 KB
01-04.txt RE 299 ms 43900 KB
01-05.txt RE 298 ms 42748 KB
01-06.txt RE 294 ms 43004 KB
01-07.txt AC 18 ms 32764 KB
01-08.txt TLE 2104 ms 43388 KB
01-09.txt RE 299 ms 43132 KB
01-10.txt TLE 2104 ms 43516 KB
01-11.txt RE 295 ms 43772 KB
01-12.txt RE 296 ms 43260 KB
01-13.txt RE 300 ms 42748 KB
01-14.txt RE 300 ms 43516 KB
sample-01.txt AC 18 ms 33660 KB