Submission #3590352


Source Code Expand

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
    long n = long.Parse(input[0]);
    long d = long.Parse(input[1]);
    long x = long.Parse(input[2]);
    float answer = 0;

    for(int i = 0; i < n; i++)
    {
      answer += (2f*d + x + 4*i*x)/4;//両方向の初項
      Console.WriteLine(answer);
      answer += ProgressionTwo(0.5f, i)*(-2*d)/4;//左方向の中間項
      answer += ProgressionOne(0.5f, i)*(2*x + 4*i*d - d)/4;
      answer += ProgressionZero(0.5f, i)*(x + 2*i*d)/4;
      Console.WriteLine(answer);
      answer += ProgressionTwo(0.5f, n-1-i)*(2*d)/4;//右方向の中間項
      answer += ProgressionOne(0.5f, n-1-i)*(2*x + 4*i*d + 3*d)/4;
      answer += ProgressionZero(0.5f, n-1-i)*(x + d + 2*i*d)/4;
      Console.WriteLine(answer);
      answer += (2f*i+1) * (x+i*d) / (4*DivideMod(2,i));//左の最終項
      Console.WriteLine(answer);
      answer += (2f*n-2*i-1) * (x+i*d+n*d) / (4*DivideMod(2,n-1-i));//右の最終項
      Console.WriteLine(answer);
    }
		//Console.WriteLine(answer);
	}

  static float ProgressionZero(float ratio, long n)
  {//等比数列の和 Σ(i=1~n)ratio^i = ratio + ratio^2 + ... + ratio^n
    if(n == 0) return 0;//項数が0の時
    if(ratio == 1) return n;//公比が1の時
    float product = DivideMod(ratio, n);//公比の項数乗
    float answer = ratio * (1-product) / (1-ratio);
    return answer;
  }

  static float ProgressionOne(float ratio, long n)
  {//等差×等比数列の和 Σ(i=1~n)i*ratio^i = 1*ratio + 2+ratio^2 + ... + n*ratio^n
    if(n == 0) return 0;//項数が0の時
    if(ratio == 1) return n*(n+1)/2;//公比が1の時
    float product = DivideMod(ratio, n);//公比の項数乗
    float answer = ratio * (1-product) / (1-ratio);
    answer -= n*product*ratio;
    answer /= 1-ratio;
    return answer;
  }

  static float ProgressionTwo(float ratio, long n)
  {//(等差)^2×等比数列の和 Σ(i=1~n)i^2*ratio^i = 1^2*ratio + 2^2+ratio^2 + ... + n^2*ratio^n
    if(n == 0) return 0;//項数が0の時
    if(ratio == 1) return n*(n+1)*(2*n+1)/6;//公比が1の時
    float product = DivideMod(ratio, n);//公比の項数乗
    float answer = 2 * ratio * (1-product) / (1-ratio);
    answer -= ratio;
    answer -= n*n*ratio*product;
    answer += n*n*ratio*ratio*product;
    answer -= (2*n-1)*ratio*product;
    answer /= ratio*ratio - 2*ratio + 1;
    return answer;
  }

  static float DivideMod(float x, long a)//戻り値はx^a、ただしaは整数。
  {
    long num = 2;
    float answer = 1;
    long check = a;
    float memo = x;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }
  
}

Submission Info

Submission Time
Task C - Pushing Balls
User suikameron
Language C# (Mono 4.6.2.0)
Score 0
Code Size 3100 Byte
Status WA
Exec Time 2108 ms
Memory 19284 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
WA × 3
WA × 15
TLE × 20
Set Name Test Cases
Sample example0.txt, example1.txt, example2.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, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt WA 21 ms 11092 KB
001.txt WA 20 ms 9044 KB
002.txt WA 21 ms 11092 KB
003.txt WA 21 ms 11092 KB
004.txt WA 21 ms 11092 KB
005.txt WA 20 ms 9044 KB
006.txt WA 21 ms 11092 KB
007.txt WA 21 ms 11092 KB
008.txt WA 20 ms 9044 KB
009.txt WA 21 ms 11092 KB
010.txt WA 781 ms 14672 KB
011.txt TLE 2108 ms 17108 KB
012.txt TLE 2108 ms 19284 KB
013.txt TLE 2108 ms 17108 KB
014.txt TLE 2108 ms 19284 KB
015.txt TLE 2108 ms 19284 KB
016.txt TLE 2108 ms 19028 KB
017.txt TLE 2108 ms 19156 KB
018.txt TLE 2108 ms 17108 KB
019.txt WA 1082 ms 17356 KB
020.txt TLE 2108 ms 19156 KB
021.txt TLE 2108 ms 17236 KB
022.txt TLE 2108 ms 19284 KB
023.txt TLE 2108 ms 19156 KB
024.txt TLE 2108 ms 19156 KB
025.txt TLE 2108 ms 19156 KB
026.txt TLE 2108 ms 16980 KB
027.txt TLE 2108 ms 19156 KB
028.txt TLE 2108 ms 19156 KB
029.txt TLE 2108 ms 19284 KB
030.txt TLE 2108 ms 19028 KB
031.txt TLE 2108 ms 19156 KB
example0.txt WA 20 ms 9044 KB
example1.txt WA 20 ms 9044 KB
example2.txt WA 50 ms 11220 KB