結果
| 問題 |
No.1307 Rotate and Accumulate
|
| コンテスト | |
| ユーザー |
fgwiebfaoish
|
| 提出日時 | 2020-12-04 03:05:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 1,068 ms / 5,000 ms |
| コード長 | 4,160 bytes |
| コンパイル時間 | 2,582 ms |
| コンパイル使用メモリ | 113,044 KB |
| 実行使用メモリ | 68,624 KB |
| 最終ジャッジ日時 | 2024-09-14 13:50:30 |
| 合計ジャッジ時間 | 13,571 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Diagnostics;
//using nint=System.Int32;
static class Program{
const int mod=(int)1e9+7;
static void Main(){
Sc sc=new Sc();
var s=sc.Ia;
var a=sc.Ia;
var r=sc.Ia;
var b=new long[s[0]];
var h=new int[s[0]];
var z=new int[s[0]*2];
for(int i = 0;i<s[1];i++) {h[r[i]]++;}
for(int i = 0;i<s[0];i++) {
z[s[0]-i-1]=a[i];
z[s[0]-i-1+s[0]]=a[i];
}
var c=Ex.Fft(z,h);
var ans=new long[s[0]];
for(int i = 0;i<s[0];i++) {ans[i]=c[c.Length-s[0]-i];}
Console.WriteLine("{0}",string.Join(" ",ans));
}
}
static class Ex{
public static long[] Fft(int[] a,int[] b){
int m=1,p=0;
while(m<a.Length+b.Length){m<<=1;p++;}
Complex[] aa=new Complex[m],ba=new Complex[m],c=new Complex[m];
var d=new long[a.Length+b.Length-1];
for(int i = 0;i<a.Length;i++) {aa[i]=a[i];}
for(int i = 0;i<b.Length;i++) {ba[i]=b[i];}
Dft(aa,p);
Dft(ba,p);
for(int i = 0;i<m;i++) {c[i]=aa[i]*ba[i];}
Idft(c,p);
for(int i = 0;i<d.Length;i++) {d[i]=(long)Round(c[i].Real/c.Length);}
return d;
}
public static void Dft(Complex[] a,int h){
for(int i=0;i<a.Length;i++) {
int j=0;
for (int k=0;k<h;k++){j|=(i>>k&1)<<(h-1-k);}
if(i<j){(a[i],a[j])=(a[j],a[i]);}
}
for(int b=1,p=1;b<a.Length;b<<=1,p++) {
for (int j = 0;j<b;j++) {
var w=Complex.FromPolarCoordinates(1,2*PI/(b<<1)*j);
for (int k = 0;k<a.Length;k+=b<<1) {
var s=a[j+k];
var t=a[j+k+b]*w;
a[j+k]=s+t;
a[j+k+b]=s-t;
}
}
}
}
public static void Idft(Complex[] a,int h){
for(int i=0;i<a.Length;i++) {
int j=0;
for (int k=0;k<h;k++){j|=(i>>k&1)<<(h-1-k);}
if(i<j){(a[i],a[j])=(a[j],a[i]);}
}
for(int b=1,p=1;b<a.Length;b<<=1,p++) {
for (int j = 0;j<b;j++) {
var w=Complex.FromPolarCoordinates(1,2*PI/(b<<1)*-j);
for (int k = 0;k<a.Length;k+=b<<1) {
var s=a[j+k];
var t=a[j+k+b]*w;
a[j+k]=s+t;
a[j+k+b]=s-t;
}
}
}
}
}
public class Sc{
public int I{get{return int.Parse(Console.ReadLine());}}
public long L{get{return long.Parse(Console.ReadLine());}}
public double D{get{return double.Parse(Console.ReadLine());}}
public string S{get{return Console.ReadLine();}}
public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
public string[] Sa{get{return Console.ReadLine().Split();}}
public object[] Oa{get{return Console.ReadLine().Split();}}
public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
fgwiebfaoish